]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Repair failure with SubPlans in multi-row VALUES lists.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Nov 2017 19:15:48 +0000 (14:15 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Nov 2017 19:15:48 +0000 (14:15 -0500)
commitae6ed07841766867ab7c0f04b996deee140dba19
treeb531e9b52cb47ac9d899b2756cb17fa79663af2b
parent1a164f940b10ad327548c747f4c45e83906784ba
Repair failure with SubPlans in multi-row VALUES lists.

When nodeValuesscan.c was written, it was impossible to have a SubPlan in
VALUES --- any sub-SELECT there would have to be uncorrelated and thereby
would produce an InitPlan instead.  We therefore took a shortcut in the
logic that throws away a ValuesScan's per-row expression evaluation data
structures.  This was broken by the introduction of LATERAL however; a
sub-SELECT containing a lateral reference produces a correlated SubPlan.

The cleanest fix for this would be to give up the optimization of
discarding the expression eval state.  But that still seems pretty
unappetizing for long VALUES lists.  It seems to work to just prevent
the subexpressions from hooking into the ValuesScan node's subPlan
list, so let's do that and see how well it works.  (If this breaks,
due to additional connections between the subexpressions and the outer
query structures, we might consider compromises like throwing away data
only for VALUES rows not containing SubPlans.)

Per bug #14924 from Christian Duta.  Back-patch to 9.3 where LATERAL
was introduced.

Discussion: https://postgr.es/m/20171124120836.1463.5310@wrigleys.postgresql.org
src/backend/executor/nodeValuesscan.c
src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql