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

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, guofenglinux(at)gmail(dot)com
Subject: Re: [PG19] Stale state after the join removal restart gives wrong results
Date: 2026-10-13 14:23:26
Message-ID: CAGRkXqRtF4KT3x7GykmvhsQ+i4CNU-JT2oLrW2F21ZqKdk-vCg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Tom,

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Concretely, the attached fixes the given test case and passes
> check-world; but I've not tried harder than that to break it.

I like this better than my 0001, and I could not break it. I kept
0001 small only because of where 19 is. If you think moving the call
is right for 19 and 18 too, I am fine with that.

I did a simple fuzz test generating 2200 random self join queries giving
the same results as 18.6 and the same plans as master. Tests pass
on REL_19_STABLE and REL_18_STABLE too.

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

0002 is still needed, the Assert fires with only your patch.

I also hit one more of that kind. Self join elimination leaves the
removed rel's securityQuals in its rte, now pointing at the kept rel.
When a later pass removes the kept rel too, the same Assert fires.

create table r (k int primary key, v int);
alter table r enable row level security;
create policy p on r using (v > 0);
create table x (k int primary key);
create role u1;
grant select on r, x to u1;
set role u1;
select x.k from x left join (r a join r b on a.k = b.k) on x.k = a.k;

I will send a patch to address ^^^^^ later today.

Thanks,
Shihao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-10-13 14:25:11 Re: postgres_fdw: Emit message when batch_size is reduced
Previous Message harrisontbooth 2026-10-13 14:03:30 [PATCH] pg_test_fsync: close Windows alarm thread handles