From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions
Date: Tue, 17 Jan 2023 03:37:31 +0000
Message-ID: <E1pHcmx-00448R-Fb@gemulon.postgresql.org> (raw)
Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions
In 1349d2790, we gave the planner the ability to provide ORDER BY/DISTINCT
Aggrefs with presorted input so that nodeAgg would not have to perform
sorts during execution. That commit failed to properly consider the
implications of if the Aggref had a volatile function in its ORDER
BY/DISTINCT clause. As it happened, this resulted in an ERROR about the
volatile function being missing from the targetlist.
Here, instead of adding the volatile function to the targetlist, we just
never consider an Aggref with a volatile function in its ORDER BY/DISTINCT
clause when choosing which Aggrefs we should sort by. We do this as if we
were to choose a plan which provided these aggregates with presorted
input, then if there were many such aggregates which could all share the
same sort order, then it may be surprising if they all shared the same
sort sometimes and didn't at other times when some other set of aggregates
were given presorted results. We can avoid this inconsistency by just
never providing these volatile function aggregates with presorted input.
Reported-by: Dean Rasheed
Discussion: https://postgr.es/m/CAEZATCWETioXs5kY8vT6BVguY41_wD962VDk=u_Nvd7S1UXzuQ@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/da5800d5fa636c6e10c9c98402d872c76aa1c8d0
Modified Files
--------------
src/backend/optimizer/plan/planner.c | 55 ++++++++++++++++++++++++++++----
src/test/regress/expected/aggregates.out | 19 +++++++++++
src/test/regress/sql/aggregates.sql | 11 +++++++
3 files changed, 79 insertions(+), 6 deletions(-)
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: Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions
In-Reply-To: <E1pHcmx-00448R-Fb@gemulon.postgresql.org>
References: <E1pHcmx-00448R-Fb@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