Fix sorting on extra grouping keys of child relations A Var that is needed by a join but is not a GROUP BY expression becomes an extra grouping key for partial aggregation. The EquivalenceClass for sorting on it is created when the grouped paths are generated, which is after the children of appendrels and partitionwise joins have received their EC members, so it has no child members. Sort-based partial aggregation on a child relation then failed with "could not find pathkey item to sort", as with a partitionwise join whose join clause includes a non-equality condition.
To fix, add the missing child members when the grouping pathkeys of a child relation are built. This is done by the new function add_child_rel_pathkey_equivalences(), which handles both child base relations and child joins, including keys that are nullable by an outer join within the child join. Reported-by: Robert Haas <[email protected]> Author: Richard Guo <[email protected]> Discussion: https://postgr.es/m/ca+tgmob7ism9ykrm44vjuduacchw-fy54mv5njptztl9uny...@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/8b29b8da78ea77c74ce2e6b140dcdde45ccb0268 Modified Files -------------- src/backend/optimizer/path/allpaths.c | 4 + src/backend/optimizer/path/equivclass.c | 78 +++++++++ src/include/optimizer/paths.h | 3 + src/test/regress/expected/eager_aggregate.out | 229 ++++++++++++++++++++++++++ src/test/regress/sql/eager_aggregate.sql | 27 +++ 5 files changed, 341 insertions(+)
