From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | xinwen(at)stu(dot)scu(dot)edu(dot)cn |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, Andres Freund <andres(at)anarazel(dot)de> |
Subject: | Re: BUG #17835: Two assertions failed in nodeAgg.c and execExprInterp.c with the same SQL |
Date: | 2023-03-13 15:26:14 |
Message-ID: | 1772189.1678721174@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> When executing the following query with CTE:
> WITH table1 ( column25 ) AS ( SELECT 1 ) SELECT FROM ( SELECT column25
> column12 FROM table1 ) AS alias0 GROUP BY column12 HAVING AVG ( ( SELECT 1
> FROM table1 JOIN ( SELECT AVG ( column25 ORDER BY CASE 1 WHEN column12 THEN
> ( SELECT AVG ( column12 ) FROM table1 ) END ) column14 FROM table1 ) AS
> alias3 ON alias3 . column14 = 1 ) ) = 1 ;
> I get a failed assertion with the following stacktrace:
Simplifying a bit, we get
WITH table1 ( col1 ) AS ( SELECT 1 )
SELECT AVG((
SELECT AVG ( a1.col1 ORDER BY ( SELECT AVG ( a2.col2 ) FROM table1 ) )
FROM table1 a1
))
FROM table1 AS a2(col2);
PG v10 says
ERROR: aggregate function calls cannot be nested
which seems correct: per spec, the innermost AVG actually should belong
to the outer query level that sources a2.col2. Later versions fail to
detect that the query is nonsensical and end up with nonsensical
executor state instead. I bisected this to
69c3936a1499b772a749ae629fc59b2d72722332 is the first bad commit
commit 69c3936a1499b772a749ae629fc59b2d72722332
Author: Andres Freund <andres(at)anarazel(dot)de>
Date: Tue Jan 9 13:25:38 2018 -0800
Expression evaluation based aggregate transition invocation.
So that commit broke something about the nested-aggregate detection
logic. It's not completely gone: if we simplify this to
WITH table1 ( col1 ) AS ( SELECT 1 )
SELECT AVG((
SELECT AVG ( ( SELECT AVG ( a2.col2 ) FROM table1 ) )
FROM table1 a1
))
FROM table1 AS a2(col2);
we still get
ERROR: aggregate function calls cannot be nested
LINE 3: SELECT AVG ( ( SELECT AVG ( a2.col2 ) FROM table1 ) )
^
v10 detected this in ExecInitAgg, while later versions are trying to
do it in the parser, but evidently there's some gap there ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Verite | 2023-03-13 15:49:14 | Re: disable pipeline mode |
Previous Message | PG Bug reporting form | 2023-03-13 12:40:11 | BUG #17837: The potential risks associated with executing "commit" in a procedure. |