summaryrefslogtreecommitdiff
path: root/src/backend/tcop/dest.c
diff options
context:
space:
mode:
authorDavid Rowley2022-12-15 21:31:25 +0000
committerDavid Rowley2022-12-15 21:31:25 +0000
commitac998020802b742303979a13692afa7b2084d0e9 (patch)
treec731037569f34cc2f52c1d94c13c1130c2e41959 /src/backend/tcop/dest.c
parentd35a1af468162f510b6139bf81a7a41fd8ba8500 (diff)
Speed up creation of command completion tags
The building of command completion tags could often be seen showing up in profiles when running high tps workloads. The query completion tags were being built with snprintf, which is slow at the best of times when compared with more manual ways of formatting strings. Here we introduce BuildQueryCompletionString() to do this job for us. We also now store the completion tag's strlen in the CommandTagBehavior struct so that we can quickly memcpy this number of bytes into the completion tag string. Appending the rows affected is done via pg_ulltoa_n. BuildQueryCompletionString returns the length of the built string. This saves us having to call strlen to figure out how many bytes to pass to pq_putmessage(). Author: David Rowley, Andres Freund Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CAHoyFK-Xwqc-iY52shj0G+8K9FJpse+FuZ36XBKy78wDVnd=Qg@mail.gmail.com
Diffstat (limited to 'src/backend/tcop/dest.c')
-rw-r--r--src/backend/tcop/dest.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/src/backend/tcop/dest.c b/src/backend/tcop/dest.c
index 6afaa153cad..e879304ae1c 100644
--- a/src/backend/tcop/dest.c
+++ b/src/backend/tcop/dest.c
@@ -166,8 +166,7 @@ void
EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
{
char completionTag[COMPLETION_TAG_BUFSIZE];
- CommandTag tag;
- const char *tagname;
+ Size len;
switch (dest)
{
@@ -175,29 +174,9 @@ EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_o
case DestRemoteExecute:
case DestRemoteSimple:
- /*
- * We assume the tagname is plain ASCII and therefore requires no
- * encoding conversion.
- */
- tag = qc->commandTag;
- tagname = GetCommandTagName(tag);
-
- /*
- * In PostgreSQL versions 11 and earlier, it was possible to
- * create a table WITH OIDS. When inserting into such a table,
- * INSERT used to include the Oid of the inserted record in the
- * completion tag. To maintain compatibility in the wire
- * protocol, we now write a "0" (for InvalidOid) in the location
- * where we once wrote the new record's Oid.
- */
- if (command_tag_display_rowcount(tag) && !force_undecorated_output)
- snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
- tag == CMDTAG_INSERT ?
- "%s 0 " UINT64_FORMAT : "%s " UINT64_FORMAT,
- tagname, qc->nprocessed);
- else
- snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "%s", tagname);
- pq_putmessage('C', completionTag, strlen(completionTag) + 1);
+ len = BuildQueryCompletionString(completionTag, qc,
+ force_undecorated_output);
+ pq_putmessage('C', completionTag, len + 1);
case DestNone:
case DestDebug: