Fix assorted missing logic for GroupingFunc nodes.
authorTom Lane <[email protected]>
Mon, 21 Mar 2022 21:44:29 +0000 (17:44 -0400)
committerTom Lane <[email protected]>
Mon, 21 Mar 2022 21:44:29 +0000 (17:44 -0400)
commit2afa031ac552995e2b6ba5371388bff280e7cfe8
treecd158e264fccf6191350b115aa3c94b52402b100
parent0de9b999d14f7c529c0a47b24198442b404db084
Fix assorted missing logic for GroupingFunc nodes.

The planner needs to treat GroupingFunc like Aggref for many purposes,
in particular with respect to processing of the argument expressions,
which are not to be evaluated at runtime.  A few places hadn't gotten
that memo, notably including subselect.c's processing of outer-level
aggregates.  This resulted in assertion failures or wrong plans for
cases in which a GROUPING() construct references an outer aggregation
level.

Also fix missing special cases for GroupingFunc in cost_qual_eval
(resulting in wrong cost estimates for GROUPING(), although it's
not clear that that would affect plan shapes in practice) and in
ruleutils.c (resulting in excess parentheses in pretty-print mode).

Per bug #17088 from Yaoguang Chen.  Back-patch to all supported
branches.

Richard Guo, Tom Lane

Discussion: https://postgr.es/m/17088-e33882b387de7f5c@postgresql.org
src/backend/nodes/nodeFuncs.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/subselect.c
src/backend/utils/adt/ruleutils.c
src/test/regress/expected/groupingsets.out
src/test/regress/sql/groupingsets.sql