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 <guofengli...@gmail.com> Reviewed-by: Dean Rasheed <dean.a.rash...@gmail.com> Discussion: https://postgr.es/m/cambws4-vxdei1v+hzylxpov0rijxhsckch1f46tlnhoneay...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/4c4961171577e292220d050c338020f2c6bf4c76 Modified Files -------------- src/backend/optimizer/prep/prepjointree.c | 33 ++++++++----------------------- 1 file changed, 8 insertions(+), 25 deletions(-)