pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix hypothetical problem passing the wrong GROUP BY pathkeys
Date: Wed, 17 Aug 2022 23:33:17 +0000
Message-ID: <E1oOSXE-0001pU-Pr@gemulon.postgresql.org> (raw)

Fix hypothetical problem passing the wrong GROUP BY pathkeys

1349d2790 changed things to make the planner request that the
query_pathkeys contain pathkeys for any ORDER BY / DISTINCT aggregates.
Some code added prior to that commit in db0d67db2 made it so the order
that the pathkeys appear in the group_pathkeys could be changed so that
the GROUP BY could be executed in a more optimal order which minimized
sort comparisons.  1349d2790 had to make sure that the pathkeys for any
ORDER BY / DISTINCT aggregates remained at the end of the groupby_pathkeys
and wasn't reordered, so some code was added to
add_paths_to_grouping_rel() to first strip off any pathkeys belonging to
ORDER BY / DISTINCT aggregates before passing to the function to optimize
the order of the group_pathkeys.

It seems I dropped the ball in 1349d2790 and mistakenly used the untouched
PlannerInfo.group_pathkeys to pass to get_useful_group_keys_orderings()
instead of the version that had the aggregate pathkeys removed.  It was
only the code path that was handling creating paths for
partially_grouped_rel which made this mistake.  In practice, we'll never
have any extra pathkeys to strip off when processing
partially_grouped_rel as that's only used when considering partial
paths, which we never do when there are ORDER BY / DISTINCT aggregates.
So this is just a hypothetical bug, not a live bug.  We already have the
correct pathkeys determined, so it's of no extra cost to pass the
correct variable.

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/20220817015755.GB26426@telsasoft.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/af7d270dd3c7523dad023f5761f630daa7fb2730

Modified Files
--------------
src/backend/optimizer/plan/planner.c | 3 ---
1 file changed, 3 deletions(-)



Message-ID: <E1oOSXE-0001pU-Pr@gemulon.postgresql.org>
Permalink:  ../E1oOSXE-0001pU-Pr@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oOSXE-0001pU-Pr@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: drowley@postgresql.org
  Subject: Re: pgsql: Fix hypothetical problem passing the wrong GROUP BY pathkeys
  In-Reply-To: <E1oOSXE-0001pU-Pr@gemulon.postgresql.org>
  References: <E1oOSXE-0001pU-Pr@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