pgsql: Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Don't presort ORDER BY/DISTINCT Aggrefs with volatile functions
Date
Msg-id E1pHcmx-00448R-Fb@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Create common infrastructure for cross-version upgrade testing.
Next
From: Michael Paquier
Date:
Subject: pgsql: Track behavior of \1 in pg_ident.conf when quoted