mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +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:
@ -10,7 +10,7 @@
|
||||
*
|
||||
* Formerly, CTAS was implemented as a variant of SELECT, which led
|
||||
* to assorted legacy behaviors that we still try to preserve, notably that
|
||||
* we must return a tuples-processed count in the completionTag. (We no
|
||||
* we must return a tuples-processed count in the QueryCompletion. (We no
|
||||
* longer do that for CTAS ... WITH NO DATA, however.)
|
||||
*
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
@ -225,7 +225,7 @@ create_ctas_nodata(List *tlist, IntoClause *into)
|
||||
ObjectAddress
|
||||
ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
|
||||
ParamListInfo params, QueryEnvironment *queryEnv,
|
||||
char *completionTag)
|
||||
QueryCompletion *qc)
|
||||
{
|
||||
Query *query = castNode(Query, stmt->query);
|
||||
IntoClause *into = stmt->into;
|
||||
@ -270,7 +270,7 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
|
||||
ExecuteStmt *estmt = castNode(ExecuteStmt, query->utilityStmt);
|
||||
|
||||
Assert(!is_matview); /* excluded by syntax */
|
||||
ExecuteQuery(pstate, estmt, into, params, dest, completionTag);
|
||||
ExecuteQuery(pstate, estmt, into, params, dest, qc);
|
||||
|
||||
/* get object address that intorel_startup saved for us */
|
||||
address = ((DR_intorel *) dest)->reladdr;
|
||||
@ -352,11 +352,9 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
|
||||
/* run the plan to completion */
|
||||
ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);
|
||||
|
||||
/* save the rowcount if we're given a completionTag to fill */
|
||||
if (completionTag)
|
||||
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
|
||||
"SELECT " UINT64_FORMAT,
|
||||
queryDesc->estate->es_processed);
|
||||
/* save the rowcount if we're given a qc to fill */
|
||||
if (qc)
|
||||
SetQueryCompletion(qc, CMDTAG_SELECT, queryDesc->estate->es_processed);
|
||||
|
||||
/* get object address that intorel_startup saved for us */
|
||||
address = ((DR_intorel *) dest)->reladdr;
|
||||
|
Reference in New Issue
Block a user