mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
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/981A9DB4-3F0C-4DA5-88AD-CB9CFF4D6CAD@enterprisedb.com
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user