Represent command completion tags as structs
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 2 Mar 2020 21:19:51 +0000 (18:19 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 2 Mar 2020 21:19:51 +0000 (18:19 -0300)
commit2f9661311b83dc481fc19f6e3bda015392010a40
tree9a1aabe1d15ac894f7badbc886ae33f16bbfc3b6
parent7b425a5283cb2c8a452c2e79d6218e41373fd641
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
39 files changed:
contrib/pg_stat_statements/pg_stat_statements.c
contrib/sepgsql/hooks.c
doc/src/sgml/event-trigger.sgml
src/backend/commands/createas.c
src/backend/commands/event_trigger.c
src/backend/commands/matview.c
src/backend/commands/portalcmds.c
src/backend/commands/prepare.c
src/backend/executor/execMain.c
src/backend/executor/functions.c
src/backend/executor/spi.c
src/backend/replication/logical/decode.c
src/backend/replication/walsender.c
src/backend/tcop/Makefile
src/backend/tcop/cmdtag.c [new file with mode: 0644]
src/backend/tcop/dest.c
src/backend/tcop/postgres.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/backend/utils/cache/evtcache.c
src/backend/utils/cache/plancache.c
src/backend/utils/mmgr/portalmem.c
src/include/commands/createas.h
src/include/commands/event_trigger.h
src/include/commands/matview.h
src/include/commands/portalcmds.h
src/include/commands/prepare.h
src/include/tcop/cmdtag.h [new file with mode: 0644]
src/include/tcop/cmdtaglist.h [new file with mode: 0644]
src/include/tcop/dest.h
src/include/tcop/pquery.h
src/include/tcop/utility.h
src/include/utils/evtcache.h
src/include/utils/plancache.h
src/include/utils/portal.h
src/pl/plperl/plperl.c
src/pl/plpgsql/src/pl_exec.c
src/pl/tcl/pltcl.c
src/test/modules/test_ddl_deparse/test_ddl_deparse.c