Fix parser failure with whole-row join alias Vars When a query has aggregates or GROUP BY, parseCheckAggregates() flattens join alias Vars in the grouping expressions, target list and HAVING clause so that aliased and unaliased references compare equal. The parser has no PlannerInfo, so this relies on every join alias expression being able to carry varnullingrels without a PHV. That doesn't hold for a whole-row Var of a join on the nullable side of an outer join: it expands to a RowExpr, and pushing the nulling bits down into its fields would turn a NULL row into ROW(NULL, ...). Such queries therefore failed with "unsupported join alias expression".
To fix, leave a nulled whole-row join Var unexpanded when no root is available. The planner expands it later and wraps it in a PlaceHolderVar as before. Nothing is lost for GROUP BY matching: a nulled whole-row Var can only be equal to the same Var, never to an expression over the join's columns. This has been broken since the introduction of varnullingrels in v16. Author: Richard Guo <[email protected]> Discussion: https://postgr.es/m/CAMbWs49q_gvoeOoF0+KZ-DpQaDb=ngffsgrz2v_n1_64l4z...@mail.gmail.com Backpatch-through: 16 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f73794bc12acc126351326580577c56f023a479a Modified Files -------------- src/backend/optimizer/util/var.c | 11 ++++++++++- src/test/regress/expected/join.out | 29 +++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 13 +++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-)
