Re: Crash with a CUBE query on 9.6

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Subject: Re: Crash with a CUBE query on 9.6
Date: 2016-12-19 19:37:20
Message-ID: 4846.1482176240@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Heikki Linnakangas <hlinnaka(at)iki(dot)fi> writes:
> The attached test case crashes on REL9_6_STABLE and master. On 9.5, it
> worked.

As best I can tell, this is the fault of commit 804163bc2. The problem
query can be simplified to

SELECT
STDDEV(DISTINCT floor(sale.cn)),
AVG(DISTINCT floor(sale.cn))
FROM sale,vendor
WHERE sale.vn=vendor.vn
GROUP BY CUBE((sale.cn,sale.dt,sale.dt),(sale.pn,sale.prc),(sale.qty,sale.vn)),sale.qty order by 1,2 ;

The two aggregates share a "pertrans" state, but finalize_aggregates
does not account for that and calls process_ordered_aggregate_single()
twice on the same pertrans state. The second time crashes because we
already deleted the tuplesort object the first time.

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.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2016-12-19 20:49:10 Re: Crash with a CUBE query on 9.6
Previous Message Heikki Linnakangas 2016-12-19 12:59:42 Crash with a CUBE query on 9.6