postgresql/contrib/sepgsql
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
..
expected Remove gratuitous uses of deprecated SELECT INTO 2021-01-28 14:28:41 +01:00
sql Remove gratuitous uses of deprecated SELECT INTO 2021-01-28 14:28:41 +01:00
.gitignore Minor sepgsql regression test fixes. 2011-02-02 23:46:51 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
database.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
dml.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
hooks.c Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
label.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
launcher Update copyright for 2021 2021-01-02 13:06:25 -05:00
proc.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
relation.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
schema.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
selinux.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
sepgsql-regtest.te Update sepgsql to add mandatory access control for TRUNCATE 2019-11-23 10:46:44 -05:00
sepgsql.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
sepgsql.sql.in sepgsql_setcon(). 2012-03-15 16:08:40 -04:00
test_sepgsql Update sepgsql to add mandatory access control for TRUNCATE 2019-11-23 10:46:44 -05:00
uavc.c Update copyright for 2021 2021-01-02 13:06:25 -05:00