Fix sharing Agg transition state of DISTINCT or ordered aggs.
Heikki Linnakangas <heikki.linnakangas@iki.fi>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/executor/nodeAgg.c | modified | +18 −3 |
| src/test/regress/expected/aggregates.out | modified | +9 −0 |
| src/test/regress/sql/aggregates.sql | modified | +3 −0 |
Discussion
- Crash with a CUBE query on 9.6 8 messages · 2016-12-19 → 2016-12-27