pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix sorting on extra grouping keys of child relations
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix sorting on extra grouping keys of child relations
@ 2026-10-05 23:52  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2026-10-05 23:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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 <robertmhaas@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CA+Tgmob7iSM9YkRM44VjUDuaCchW-fY54MV5njpTZTL9uNyV4w@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(+)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix sorting on extra grouping keys of child relations
@ 2026-10-05 23:52  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2026-10-05 23:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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 <robertmhaas@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CA+Tgmob7iSM9YkRM44VjUDuaCchW-fY54MV5njpTZTL9uNyV4w@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/94a907baf3be0b875af2277e08b776ab9577890a

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(+)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-10-05 23:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-05 23:52 pgsql: Fix sorting on extra grouping keys of child relations Richard Guo <rguo@postgresql.org>
2026-10-05 23:52 pgsql: Fix sorting on extra grouping keys of child relations Richard Guo <rguo@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox