]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Set scan direction appropriately for SubPlans (bug #15336)
authorAndrew Gierth <rhodiumtoad@postgresql.org>
Fri, 17 Aug 2018 14:04:26 +0000 (15:04 +0100)
committerAndrew Gierth <rhodiumtoad@postgresql.org>
Fri, 17 Aug 2018 15:06:35 +0000 (16:06 +0100)
commitd31ebbff5b2bbe9dfe3fb130448581a4da388031
treea2b9d0c5daafd14099de55beb83060f027050aaf
parentbd30f51c0ec97207ac9baf68d03fd4e851f9777f
Set scan direction appropriately for SubPlans (bug #15336)

When executing a SubPlan in an expression, the EState's direction
field was left alone, resulting in an attempt to execute the subplan
backwards if it was encountered during a backwards scan of a cursor.
Also, though much less likely, it was possible to reach the execution
of an InitPlan while in backwards-scan state.

Repair by saving/restoring estate->es_direction and forcing forward
scan mode in the relevant places.

Backpatch all the way, since this has been broken since 8.3 (prior to
commit c7ff7663e, SubPlans had their own EStates rather than sharing
the parent plan's, so there was no confusion over scan direction).

Per bug #15336 reported by Vladimir Baranoff; analysis and patch by
me, review by Tom Lane.

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