Re: [PG19] Stale state after the join removal restart gives wrong results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Guofenglinux <guofenglinux(at)gmail(dot)com>
Subject: Re: [PG19] Stale state after the join removal restart gives wrong results
Date: 2026-10-13 03:15:09
Message-ID: 588480.1791861309@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

shihao zhong <zhong950419(at)gmail(dot)com> writes:
> 1. adjust_group_pathkeys_for_groupagg() sets aggpresorted on the
> aggregates it picks and nothing clears it. When self join elimination
> removes a rel and the second pass picks a different presorted group,
> the stale flag makes the executor skip the sort.

Hmm. I've not looked at exactly what that function does, but just
going by the name, why is it being called inside the restart loop
rather than later? I feel like anything to do with identifying
pathkeys could/should wait till after join removal.

> 2. A removed rel keeps its tablesample. When the sample argument
> refers to another rel that the second pass then removes,
> ChangeVarNodes hits Assert(context->new_index != INVALID_VAR) in
> rewriteManip.c. Non assert builds write INVALID_VAR into a dead rte
> and seem fine. Richard looked at the rte fields in [2] and thought
> tablesample was safe, this is the case that is not. 0002 clears
> rte->tablesample next to securityQuals.

Good catch, although I kind of wonder why we're allowing lateral
refs in tablesample clauses in the first place.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Junwang Zhao 2026-10-13 03:24:39 Re: [PATCH] numeric: canonicalize wide digit accumulation
Previous Message shihao zhong 2026-10-13 03:03:54 Re: [PG19] Stale state after the join removal restart gives wrong results