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: Disable WindowAgg inverse transitions when subplans are present
Date: Mon, 13 Feb 2023 04:08:34 +0000
Message-ID: <E1pRQ8o-000rxg-7E@gemulon.postgresql.org> (raw)

Disable WindowAgg inverse transitions when subplans are present

When an aggregate function is used as a WindowFunc and a tuple transitions
out of the window frame, we ordinarily try to make use of the aggregate
function's inverse transition function to "unaggregate" the exiting tuple.

This optimization is disabled for various cases, including when the
aggregate contains a volatile function.  In such a case we'd be unable to
ensure that the transition value was calculated to the same value during
transitions and inverse transitions.  Unfortunately, we did this check by
calling contain_volatile_functions() which does not recursively search
SubPlans for volatile functions.  If the aggregate function's arguments or
its FILTER clause contained a subplan with volatile functions then we'd
fail to notice this.

Here we fix this by just disabling the optimization when the WindowFunc
contains any subplans.  Volatile functions are not the only reason that a
subplan may have nonrepeatable results.

Bug: #17777
Reported-by: Anban Company
Discussion: https://postgr.es/m/17777-860b739b6efde977%40postgresql.org
Reviewed-by: Tom Lane
Backpatch-through: 11

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8d2a8581b6d67cfa05c1f47fa13de9815cdf91f6

Modified Files
--------------
src/backend/executor/nodeWindowAgg.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1pRQ8o-000rxg-7E@gemulon.postgresql.org>
Permalink:  ../E1pRQ8o-000rxg-7E@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pRQ8o-000rxg-7E@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: Disable WindowAgg inverse transitions when subplans are present
  In-Reply-To: <E1pRQ8o-000rxg-7E@gemulon.postgresql.org>
  References: <E1pRQ8o-000rxg-7E@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