postgresql/src/backend
Tom Lane 7c337b6b52 Centralize the logic for protective copying of utility statements.
In the "simple Query" code path, it's fine for parse analysis or
execution of a utility statement to scribble on the statement's node
tree, since that'll just be thrown away afterwards.  However it's
not fine if the node tree is in the plan cache, as then it'd be
corrupted for subsequent executions.  Up to now we've dealt with
that by having individual utility-statement functions apply
copyObject() if they were going to modify the tree.  But that's
prone to errors of omission.  Bug #17053 from Charles Samborski
shows that CREATE/ALTER DOMAIN didn't get this memo, and can
crash if executed repeatedly from plan cache.

In the back branches, we'll just apply a narrow band-aid for that,
but in HEAD it seems prudent to have a more principled fix that
will close off the possibility of other similar bugs in future.
Hence, let's hoist the responsibility for doing copyObject up into
ProcessUtility from its children, thus ensuring that it happens for
all utility statement types.

Also, modify ProcessUtility's API so that its callers can tell it
whether a copy step is necessary.  It turns out that in all cases,
the immediate caller knows whether the node tree is transient, so
this doesn't involve a huge amount of code thrashing.  In this way,
while we lose a little bit in the execute-from-cache code path due
to sometimes copying node trees that wouldn't be mutated anyway,
we gain something in the simple-Query code path by not copying
throwaway node trees.  Statements that are complex enough to be
expensive to copy are almost certainly ones that would have to be
copied anyway, so the loss in the cache code path shouldn't be much.

(Note that this whole problem applies only to utility statements.
Optimizable statements don't have the issue because we long ago made
the executor treat Plan trees as read-only.  Perhaps someday we will
make utility statement execution act likewise, but I'm not holding
my breath.)

Discussion: https://postgr.es/m/931771.1623893989@sss.pgh.pa.us
Discussion: https://postgr.es/m/17053-3ca3f501bbc212b4@postgresql.org
2021-06-18 11:22:58 -04:00
..
access Tidy up GetMultiXactIdMembers()'s behavior on error 2021-06-17 14:50:42 +03:00
bootstrap Rethink definition of pg_attribute.attcompression. 2021-05-27 13:24:27 -04:00
catalog Don't set a fast default for anything but a plain table 2021-06-18 06:51:12 -04:00
commands Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
executor Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
lib Fix typo in comment 2021-04-20 14:35:16 +02:00
libpq Fix RADIUS error reporting in hba file parsing 2021-05-31 18:43:48 +02:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
optimizer Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
parser Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
partitioning Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
po Translation updates 2021-05-17 14:30:27 +02:00
port Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
postmaster Make archiver process handle barrier events. 2021-06-18 17:57:09 +09:00
regex Fix performance issue in new regex match-all detection code. 2021-05-03 11:42:31 -04:00
replication Improve SQLSTATE reporting in some replication-related code. 2021-06-16 11:52:05 -04:00
rewrite Adjust locations which have an incorrect copyright year 2021-06-04 12:19:50 +12:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Fix an asssortment of typos in brin_minmax_multi.c and mcv.c 2021-06-10 20:13:44 +12:00
storage Remove pg_wait_for_backend_termination(). 2021-06-14 17:29:37 -07:00
tcop Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
tsearch Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
utils Revert 29854ee8d1 due to buildfarm failures 2021-06-15 21:44:40 +03:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Use sort_template.h for qsort_tuple() and qsort_ssup(). 2021-03-03 17:02:32 +13:00
nls.mk Translation updates 2021-05-10 14:36:21 +02:00