Skip to content

Commit 4c49611

Browse files
author
Richard Guo
committed
Remove code setting wrap_non_vars to true for UNION ALL subqueries
In pull_up_simple_subquery and pull_up_constant_function, there is code that sets wrap_non_vars to true when dealing with an appendrel member. The goal is to wrap subquery outputs that are not simple Vars in PlaceHolderVars, ensuring that what we pull up doesn't get merged into a surrounding expression during later processing, which could cause it to fail to match the expression actually available from the appendrel. However, this is unnecessary. When pulling up an appendrel child subquery, the only part of the upper query that could reference the appendrel child yet is the translated_vars list of the associated AppendRelInfo that we just made for this child. Furthermore, we do not want to force use of PHVs in the AppendRelInfo, as there is no outer join between. In fact, perform_pullup_replace_vars always sets wrap_non_vars to false before performing pullup_replace_vars on the AppendRelInfo. This patch simply removes the code that sets wrap_non_vars to true for UNION ALL subqueries. Author: Richard Guo <[email protected]> Reviewed-by: Dean Rasheed <[email protected]> Discussion: https://postgr.es/m/CAMbWs4-VXDEi1v+hZYLxpOv0riJxHsCkCH1f46tLnhonEAyGCQ@mail.gmail.com
1 parent d3b2e5e commit 4c49611

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

src/backend/optimizer/prep/prepjointree.c

+8-25
Original file line numberDiff line numberDiff line change
@@ -1440,24 +1440,14 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
14401440
rvcontext.rv_cache = palloc0((list_length(subquery->targetList) + 1) *
14411441
sizeof(Node *));
14421442

1443-
/*
1444-
* If we are dealing with an appendrel member then anything that's not a
1445-
* simple Var has to be turned into a PlaceHolderVar. We force this to
1446-
* ensure that what we pull up doesn't get merged into a surrounding
1447-
* expression during later processing and then fail to match the
1448-
* expression actually available from the appendrel.
1449-
*/
1450-
if (containing_appendrel != NULL)
1451-
rvcontext.wrap_non_vars = true;
1452-
14531443
/*
14541444
* If the parent query uses grouping sets, we need a PlaceHolderVar for
1455-
* anything that's not a simple Var. Again, this ensures that expressions
1456-
* retain their separate identity so that they will match grouping set
1457-
* columns when appropriate. (It'd be sufficient to wrap values used in
1458-
* grouping set columns, and do so only in non-aggregated portions of the
1459-
* tlist and havingQual, but that would require a lot of infrastructure
1460-
* that pullup_replace_vars hasn't currently got.)
1445+
* anything that's not a simple Var. This ensures that expressions retain
1446+
* their separate identity so that they will match grouping set columns
1447+
* when appropriate. (It'd be sufficient to wrap values used in grouping
1448+
* set columns, and do so only in non-aggregated portions of the tlist and
1449+
* havingQual, but that would require a lot of infrastructure that
1450+
* pullup_replace_vars hasn't currently got.)
14611451
*/
14621452
if (parse->groupingSets)
14631453
rvcontext.wrap_non_vars = true;
@@ -2159,17 +2149,10 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode,
21592149
rvcontext.rv_cache = palloc0((list_length(rvcontext.targetlist) + 1) *
21602150
sizeof(Node *));
21612151

2162-
/*
2163-
* If we are dealing with an appendrel member then anything that's not a
2164-
* simple Var has to be turned into a PlaceHolderVar. (See comments in
2165-
* pull_up_simple_subquery().)
2166-
*/
2167-
if (containing_appendrel != NULL)
2168-
rvcontext.wrap_non_vars = true;
2169-
21702152
/*
21712153
* If the parent query uses grouping sets, we need a PlaceHolderVar for
2172-
* anything that's not a simple Var.
2154+
* anything that's not a simple Var. (See comments in
2155+
* pull_up_simple_subquery().)
21732156
*/
21742157
if (parse->groupingSets)
21752158
rvcontext.wrap_non_vars = true;

0 commit comments

Comments
 (0)