pgsql: Further fixes for MULTIEXPR_SUBLINK fix. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Further fixes for MULTIEXPR_SUBLINK fix.
Date
Msg-id E1oVfLD-001klC-KW@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Further fixes for MULTIEXPR_SUBLINK fix.

Some more things I didn't think about in commits 3f7323cbb et al:

MULTIEXPR_SUBLINK subplans might have been converted to initplans
instead of regular subplans, in which case they won't show up in
the modified targetlist.  Fortunately, this would only happen if
they have no input parameters, which means that the problem we
originally needed to fix can't happen with them.  Therefore, there's
no need to clone their output parameters, and thus it doesn't hurt
that we'll fail to see them in the first pass over the targetlist.
Nonetheless, this complicates matters greatly, because now we have
to distinguish output Params of initplans (which shouldn't get
renumbered) from those of regular subplans (which should).
This also breaks the simplistic scheme I used of assuming that the
subplans found in the targetlist have consecutive subLinkIds.
We really can't avoid the need to know the subplans' subLinkIds in
this code.  To fix that, add subLinkId as the last field of SubPlan.
We can get away with that change in back branches because SubPlan
nodes will never be stored in the catalogs, and there's no ABI
break for external code that might be looking at the existing
fields of SubPlan.

Secondly, rewriteTargetListIU might have rolled up multiple
FieldStores or SubscriptingRefs into one targetlist entry,
breaking the assumption that there's at most one Param to fix
per targetlist entry.  (That assumption is OK I think in the
ruleutils.c code I stole the logic from in 18f51083c, because
that only deals with pre-rewrite query trees.  But it's
definitely not OK here.)  Abandon that shortcut and just do a
full tree walk on the targetlist to ensure we find all the
Params we have to change.

Per bug #17606 from Andre Lin.  As before, only v10-v13 need the
patch.

Discussion: https://postgr.es/m/17606-e5c8ad18d31db96a@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9bcf6fb281de1a30cd6ced443451d5ab9ac4447f

Modified Files
--------------
src/backend/nodes/copyfuncs.c          |   1 +
src/backend/nodes/equalfuncs.c         |   1 +
src/backend/nodes/outfuncs.c           |   1 +
src/backend/nodes/readfuncs.c          |   1 +
src/backend/optimizer/plan/subselect.c | 139 +++++++++++++++++----------------
src/include/nodes/primnodes.h          |   2 +
src/test/regress/expected/inherit.out  |  41 +++++++---
src/test/regress/sql/inherit.sql       |  16 ++--
8 files changed, 119 insertions(+), 83 deletions(-)


pgsql-committers by date:

Previous
From: John Naylor
Date:
Subject: pgsql: Fix cplusplusscheck in vpath builds
Next
From: noreply@postgresql.org
Date:
Subject: pgsql: Tag refs/tags/REL_15_BETA4 was created