]> git.ipfire.org Git - thirdparty/postgresql.git/commit
When replanning a plpgsql "simple expression", check it's still simple.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Jun 2024 17:37:46 +0000 (13:37 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Jun 2024 17:37:50 +0000 (13:37 -0400)
commit1450db793f643991e4684fa8b5cee6ded51ab870
tree55833297ac0656177aac1f5237d6770256a98616
parentd881f6fdf5e8346cd8924d4fd671a886a39853d3
When replanning a plpgsql "simple expression", check it's still simple.

The previous coding here assumed that we didn't need to recheck any
of the querytree tests made in exec_simple_check_plan().  I think
we supposed that those properties were fully determined by the
syntax of the source text and hence couldn't change.  That is true
for most of them, but at least hasTargetSRFs and hasAggs can change
by dint of forcibly dropping an originally-referenced function and
recreating it with new properties.  That leads to "unexpected plan
node type" or similar failures.

These tests are pretty cheap compared to the cost of replanning, so
rather than sweat over exactly which properties need to be rechecked,
let's just recheck them all.  Hence, factor out those tests into a new
function exec_is_simple_query(), and rearrange callers as needed.

A second problem in the same area was that if we failed during
replanning or during exec_save_simple_expr(), we'd potentially
leave behind now-dangling pointers to the old simple expression,
potentially resulting in crashes later.  To fix, clear those pointers
before replanning.

The v12 code looks quite different in this area but still has the
bug about needing to recheck query simplicity.  I chose to back-patch
all of the plpgsql_simple.sql test script, which formerly didn't exist
in this branch.

Per bug #18497 from Nikita Kalinin.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18497-fe93b6da82ce31d4@postgresql.org
src/pl/plpgsql/src/expected/plpgsql_simple.out
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/sql/plpgsql_simple.sql