Represent command completion tags as structs

Alvaro Herrera <alvherre@alvh.no-ip.org>

Commit: 2f9661311b83dc481fc19f6e3bda015392010a40
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: 2020-03-02T21:19:51Z
Releases: 13.0
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

Files

PathChange+/−
contrib/pg_stat_statements/pg_stat_statements.c modified +8 −12
contrib/sepgsql/hooks.c modified +3 −3
doc/src/sgml/event-trigger.sgml modified +1 −1
src/backend/commands/createas.c modified +6 −8
src/backend/commands/event_trigger.c modified +22 −138
src/backend/commands/matview.c modified +1 −1
src/backend/commands/portalcmds.c modified +7 −9
src/backend/commands/prepare.c modified +2 −2
src/backend/executor/execMain.c modified +2 −2
src/backend/executor/functions.c modified +2 −2
src/backend/executor/spi.c modified +10 −11
src/backend/replication/logical/decode.c modified +1 −1
src/backend/replication/walsender.c modified +14 −4
src/backend/tcop/cmdtag.c added +98 −0
src/backend/tcop/dest.c modified +26 −6
src/backend/tcop/Makefile modified +1 −0
src/backend/tcop/postgres.c modified +14 −19
src/backend/tcop/pquery.c modified +44 −68
src/backend/tcop/utility.c modified +274 −287
src/backend/utils/cache/evtcache.c modified +16 −14
src/backend/utils/cache/plancache.c modified +4 −4
src/backend/utils/mmgr/portalmem.c modified +4 −2
src/include/commands/createas.h modified +2 −1
src/include/commands/event_trigger.h modified +2 −1
src/include/commands/matview.h modified +1 −1
src/include/commands/portalcmds.h modified +1 −1
src/include/commands/prepare.h modified +1 −1
src/include/tcop/cmdtag.h added +58 −0
src/include/tcop/cmdtaglist.h added +218 −0
src/include/tcop/dest.h modified +4 −2
src/include/tcop/pquery.h modified +1 −1
src/include/tcop/utility.h modified +11 −4
src/include/utils/evtcache.h modified +1 −2
src/include/utils/plancache.h modified +4 −3
src/include/utils/portal.h modified +4 −2
src/pl/plperl/plperl.c modified +1 −1
src/pl/plpgsql/src/pl_exec.c modified +5 −5
src/pl/tcl/pltcl.c modified +2 −1
src/test/modules/test_ddl_deparse/test_ddl_deparse.c modified +1 −1

Documentation touched

Discussion