]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix planner error with multiple copies of an AlternativeSubPlan.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Sep 2021 19:11:21 +0000 (15:11 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Sep 2021 19:11:21 +0000 (15:11 -0400)
commit29aa0ce361d16a79e4ebf7561cbb16ed1d0e2211
tree2c70d2776496f123478f10232a211b1372b05d21
parent4e86887e0922f20add67e2473c7baae8c7f05d5e
Fix planner error with multiple copies of an AlternativeSubPlan.

It's possible for us to copy an AlternativeSubPlan expression node
into multiple places, for example the scan quals of several
partition children.  Then it's possible that we choose a different
one of the alternatives as optimal in each place.  Commit 41efb8340
failed to consider this scenario, so its attempt to remove "unused"
subplans could remove subplans that were still used elsewhere.

Fix by delaying the removal logic until we've examined all the
AlternativeSubPlans in a given query level.  (This does assume that
AlternativeSubPlans couldn't get copied to other query levels, but
for the foreseeable future that's fine; cf qual_is_pushdown_safe.)

Per report from Rajkumar Raghuwanshi.  Back-patch to v14
where the faulty logic came in.

Discussion: https://postgr.es/m/CAKcux6==O3NNZC3bZ2prRYv3cjm3_Zw1GfzmOjEVqYN4jub2+Q@mail.gmail.com
src/backend/optimizer/plan/setrefs.c
src/include/nodes/pathnodes.h
src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql