Re: Crash with a CUBE query on 9.6

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>, David Rowley <david.rowley@2ndquadrant.com>
Date: 2016-12-19T21:22:24Z
Lists: pgsql-bugs
Heikki Linnakangas <hlinnaka@iki.fi> writes:
> On 12/19/2016 09:37 PM, Tom Lane wrote:
>> Probably, the loop in finalize_aggregates needs to be split into two,
>> one over the pertrans states and then a second one over the peragg states.
>> But this code has been hacked up enough since I last looked at it that
>> I'm hesitant to try to fix it myself.

> Yes, that seems straightforward. I came up with the attached. Will 
> commit tomorrow, barring objections.

Code patch looks reasonable, but I do not get a crash on the proposed test
case with current code.  I suspect that integer avg() and sum() don't
actually share transstates, making the test case a bit off-point.

			regards, tom lane


Commits

  1. Fix sharing Agg transition state of DISTINCT or ordered aggs.

  2. Share transition state between different aggregates when possible.