pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix sorting on extra grouping keys of child relations
Date: Mon, 05 Oct 2026 23:52:21 +0000
Message-ID: <E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org>
Permalink:  ../E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org
  Subject: Re: pgsql: Fix sorting on extra grouping keys of child relations
  In-Reply-To: <E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org>
  References: <E1xDsTl-00000000TZL-0jnq@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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