v1-0001-Remove-code-setting-wrap_non_vars-to-true-for-UNION-ALL-subqueries.patch
application/octet-stream
Filename: v1-0001-Remove-code-setting-wrap_non_vars-to-true-for-UNION-ALL-subqueries.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v1-0001
Subject: Remove code setting wrap_non_vars to true for UNION ALL subqueries
| File | + | − |
|---|---|---|
| src/backend/optimizer/prep/prepjointree.c | 0 | 18 |
From 45dbbaf320e2362cffedc462e6b152bd7187ffec Mon Sep 17 00:00:00 2001 From: Richard Guo <guofenglinux@gmail.com> Date: Thu, 6 Mar 2025 18:25:11 +0900 Subject: [PATCH v1 1/2] 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 <guofenglinux@gmail.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-VXDEi1v+hZYLxpOv0riJxHsCkCH1f46tLnhonEAyGCQ@mail.gmail.com --- src/backend/optimizer/prep/prepjointree.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index bcc40dd5a84..6a4d005e6ce 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -1434,16 +1434,6 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte, rvcontext.rv_cache = palloc0((list_length(subquery->targetList) + 1) * sizeof(Node *)); - /* - * If we are dealing with an appendrel member then anything that's not a - * simple Var has to be turned into a PlaceHolderVar. We force this to - * ensure that what we pull up doesn't get merged into a surrounding - * expression during later processing and then fail to match the - * expression actually available from the appendrel. - */ - if (containing_appendrel != NULL) - rvcontext.wrap_non_vars = true; - /* * If the parent query uses grouping sets, we need a PlaceHolderVar for * anything that's not a simple Var. Again, this ensures that expressions @@ -2153,14 +2143,6 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode, rvcontext.rv_cache = palloc0((list_length(rvcontext.targetlist) + 1) * sizeof(Node *)); - /* - * If we are dealing with an appendrel member then anything that's not a - * simple Var has to be turned into a PlaceHolderVar. (See comments in - * pull_up_simple_subquery().) - */ - if (containing_appendrel != NULL) - rvcontext.wrap_non_vars = true; - /* * If the parent query uses grouping sets, we need a PlaceHolderVar for * anything that's not a simple Var. -- 2.43.0