Re: BUG #17835: Two assertions failed in nodeAgg.c and execExprInterp.c with the same SQL

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

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: xinwen@stu.scu.edu.cn, pgsql-bugs@lists.postgresql.org
Date: 2023-03-13T16:13:25Z
Lists: pgsql-bugs

Attachments

I wrote:
> v10 detected this in ExecInitAgg, while later versions are trying to
> do it in the parser, but evidently there's some gap there ...

Looking closer, 69c3936a1 didn't really break this, it just exposed
that it was already broken.  check_agg_arguments() has never gotten
this case right, but it was back-stopped by the check in ExecInitAgg,
which 69c3936a1 removed because it was no longer easy to check there.

The problem is simple: check_agg_arguments supposes that an inner
(lower level) aggregate cannot contain aggregates of outer levels,
which is just wrong on its face.  So we can't skip descending into
an aggregate's arguments.  Somebody (probably Gierth) recognized
that this was true for grouping functions, but didn't see that the
adjacent code was buggy.

			regards, tom lane

Commits

  1. Fix failure to detect some cases of improperly-nested aggregates.

  2. Expression evaluation based aggregate transition invocation.