pgsql: Fix sharing Agg transition state of DISTINCT or ordered aggs.

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix sharing Agg transition state of DISTINCT or ordered aggs.
Date: 2016-12-20 07:23:42
Message-ID: E1cJEly-0006Rt-3K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix sharing Agg transition state of DISTINCT or ordered aggs.

If a query contained two aggregates that could share the transition value,
we would correctly collect the input into a tuplesort only once, but
incorrectly run the transition function over the accumulated input twice,
in finalize_aggregates(). That caused a crash, when we tried to call
tuplesort_performsort() on an already-freed NULL tuplestore.

Backport to 9.6, where sharing of transition state and this bug were
introduced.

Analysis by Tom Lane.

Discussion: https://www.postgresql.org/message-id/ac5b0b69-744c-9114-6218-8300ac920e61@iki.fi

Branch
------
REL9_6_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/ce92fc4e2540d0ce554e498adb27f0ef29199b94

Modified Files
--------------
src/backend/executor/nodeAgg.c | 21 ++++++++++++++++++---
src/test/regress/expected/aggregates.out | 9 +++++++++
src/test/regress/sql/aggregates.sql | 3 +++
3 files changed, 30 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2016-12-20 13:42:53 pgsql: Add pg_sequence system catalog
Previous Message Robert Haas 2016-12-20 03:56:20 pgsql: Invalid parent's relcache after CREATE TABLE .. PARTITION OF.