Re: BUG #17088: FailedAssertion in prepagg.c

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, Michael Paquier <michael(at)paquier(dot)xyz>, cyg0810(at)gmail(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17088: FailedAssertion in prepagg.c
Date: 2021-07-08 06:14:29
Message-ID: CAMbWs4_1m1Xd2JfCHFjGk9=Pj1gTiicYwG1JEpKLaxLub19RXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Jul 8, 2021 at 1:44 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:

>
> On Thu, Jul 8, 2021 at 5:56 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
>> Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
>> > "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>> > Tom> Hmm. Maybe it'd be better if the default behavior in
>> > Tom> expression_tree_walker/mutator did not include recursing into the
>> > Tom> args, then?
>>
>> > You'd think, but as I recall (I will re-check this to confirm) there
>> > were more places where we _did_ need to recurse (especially during parse
>> > analysis before we've matched up the sortgrouprefs), while most of the
>> > places where recursion needed to be explicitly avoided already needed
>> > special-case handling, so having the default the other way would likely
>> > have required a special-case almost everywhere.
>>
>> Fair enough. This is the kind of design choice that can be worth
>> revisiting later; but if the conclusion is still the same, fine with me.
>>
>
> I think the culprit is that when replacing correlation uplevel vars with
> Params, we do not handle the SubLinks in the arguments of uplevel
> GroupingFunc. We expect build_subplan should take care of it. But in
> build_subplan, we ignore GroupingFunc incorrectly.
>
> diff --git a/src/backend/optimizer/plan/subselect.c
> b/src/backend/optimizer/plan/subselect.c
> index 0881a208ac..e4918f275e 100644
> --- a/src/backend/optimizer/plan/subselect.c
> +++ b/src/backend/optimizer/plan/subselect.c
> @@ -364,7 +364,8 @@ build_subplan(PlannerInfo *root, Plan *plan,
> PlannerInfo *subroot,
> * SS_replace_correlation_vars). Do that now.
> */
> if (IsA(arg, PlaceHolderVar) ||
> - IsA(arg, Aggref))
> + IsA(arg, Aggref) ||
> + IsA(arg, GroupingFunc))
> arg = SS_process_sublinks(root, arg, false);
>
>

I think we also need to change SS_process_sublinks to avoid recursing
into the arguments of an outer GroupingFunc. And that leads to a fix as
attached.

Thanks
Richard

Attachment Content-Type Size
0001-Fix-GroupingFunc-assertion-failure.patch application/octet-stream 1.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Guillaume Lelarge 2021-07-08 06:50:11 Re: BUG #17091: Cannot install with EDB installer when username contains diacritics
Previous Message Richard Guo 2021-07-08 05:44:07 Re: BUG #17088: FailedAssertion in prepagg.c