pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryan Green <dbryan.green@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Fire create_upper_paths_hook for UPPERREL_PARTIAL_GROUP_AGG
Date: Wed, 26 Aug 2026 13:44:58 -0500
Message-ID: <13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com> (raw)
In-Reply-To: <6fc72a7d-9f52-4a72-9adf-1912da255605@dunslane.net>
References: <6fc72a7d-9f52-4a72-9adf-1912da255605@dunslane.net>

On 8/12/26 17:32, Andrew Dunstan wrote:
> 
> Greetings
> 
> create_partial_grouping_paths() builds the UPPERREL_PARTIAL_GROUP_AGG
> upper relation.  It already calls the FDW callback GetForeignUpperPaths
> there, but never calls create_upper_paths_hook, the general-purpose
> hook that non-FDW extensions use to add paths. UPPERREL_PARTIAL_DISTINCT
> doesn't have this gap: create_partial_distinct_paths() calls both
> GetForeignUpperPaths and create_upper_paths_hook for it.
> 
> This patch adds the missing create_upper_paths_hook call right next to
> the existing GetForeignUpperPaths call, so a non-FDW extension can add
> partial aggregation paths at the same point an FDW already can, before
> those paths are gathered and a Finalize Aggregate is built on top.
> 
> It's a small, self-contained planner change with no effect on existing
> plans unless an extension registers create_upper_paths_hook and adds
> paths at this new call site.
> 
> cheers
> 
> 
> andrew
> 
> -- 
> Andrew Dunstan
> EDB: https://www.enterprisedb.com

Andrew,

If you use enable_partitionwise_aggregate then
create_partial_grouping_paths will run once for the parent and then
again for each child. This leads to the
upper_targets[UPPERREL_PARTIAL_GROUP_AGG] assignment being overwritten
per child, resulting in upper_targets holding the last child's
reltarget. This happens whenever partitionwise aggregation is
considered-- it doesn't have to win. So any extension reading the slot
after the grouping stage gets the wrong target. I reproduced this with a
test hook.

The hook already gets the target as output_rel->reltarget, so I think we
could just drop the assignment?


bg

--
Bryan Green
EDB: https://www.enterprisedb.com






view thread (8+ messages)  latest in thread

Message-ID: <13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com>
Permalink:  ../13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com/
Also on:    postgresql.org/message-id/13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com

 · 

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-hackers@postgresql.org
  Cc: dbryan.green@gmail.com
  Subject: Re: Fire create_upper_paths_hook for UPPERREL_PARTIAL_GROUP_AGG
  In-Reply-To: <13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com>
  References: <6fc72a7d-9f52-4a72-9adf-1912da255605@dunslane.net> <13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com>

* 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