summaryrefslogtreecommitdiff
path: root/src/backend/tcop/dest.c
diff options
context:
space:
mode:
authorAlvaro Herrera2020-03-02 21:19:51 +0000
committerAlvaro Herrera2020-03-02 21:19:51 +0000
commit2f9661311b83dc481fc19f6e3bda015392010a40 (patch)
tree9a1aabe1d15ac894f7badbc886ae33f16bbfc3b6 /src/backend/tcop/dest.c
parent7b425a5283cb2c8a452c2e79d6218e41373fd641 (diff)
Represent command completion tags as structs
The backend was using strings to represent command tags and doing string comparisons in multiple places, but that's slow and unhelpful. Create a new command list with a supporting structure to use instead; this is stored in a tag-list-file that can be tailored to specific purposes with a caller-definable C macro, similar to what we do for WAL resource managers. The first first such uses are a new CommandTag enum and a CommandTagBehavior struct. Replace numerous occurrences of char *completionTag with a QueryCompletion struct so that the code no longer stores information about completed queries in a cstring. Only at the last moment, in EndCommand(), does this get converted to a string. EventTriggerCacheItem no longer holds an array of palloc’d tag strings in sorted order, but rather just a Bitmapset over the CommandTags. Author: Mark Dilger, with unsolicited help from Álvaro Herrera Reviewed-by: John Naylor, Tom Lane Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/tcop/dest.c')
-rw-r--r--src/backend/tcop/dest.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/backend/tcop/dest.c b/src/backend/tcop/dest.c
index 09c1dcbb537..7208751ec78 100644
--- a/src/backend/tcop/dest.c
+++ b/src/backend/tcop/dest.c
@@ -100,7 +100,7 @@ DestReceiver *None_Receiver = (DestReceiver *) &donothingDR;
* ----------------
*/
void
-BeginCommand(const char *commandTag, CommandDest dest)
+BeginCommand(CommandTag commandTag, CommandDest dest)
{
/* Nothing to do at present */
}
@@ -163,8 +163,12 @@ CreateDestReceiver(CommandDest dest)
* ----------------
*/
void
-EndCommand(const char *commandTag, CommandDest dest)
+EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
{
+ char completionTag[COMPLETION_TAG_BUFSIZE];
+ CommandTag tag;
+ const char *tagname;
+
switch (dest)
{
case DestRemote:
@@ -172,11 +176,27 @@ EndCommand(const char *commandTag, CommandDest dest)
case DestRemoteSimple:
/*
- * We assume the commandTag is plain ASCII and therefore requires
- * no encoding conversion.
+ * We assume the tagname is plain ASCII and therefore requires no
+ * encoding conversion.
+ *
+ * We no longer display LastOid, but to preserve the wire
+ * protocol, we write InvalidOid where the LastOid used to be
+ * written.
+ *
+ * All cases where LastOid was written also write nprocessed
+ * count, so just Assert that rather than having an extra test.
*/
- pq_putmessage('C', commandTag, strlen(commandTag) + 1);
- break;
+ tag = qc->commandTag;
+ tagname = GetCommandTagName(tag);
+
+ 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);
case DestNone:
case DestDebug: