Re: remove_useless_joins vs. bug #19560 - Mailing list pgsql-hackers

From Richard Guo
Subject Re: remove_useless_joins vs. bug #19560
Date
Msg-id CAMbWs484SQSdzWTgZYKvwtuC6J4m7acw0LfBjp3aWPvav7gC_w@mail.gmail.com
Whole thread
In response to Re: remove_useless_joins vs. bug #19560  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: remove_useless_joins vs. bug #19560
List pgsql-hackers
On Fri, Aug 28, 2026 at 10:43 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Sold.  I'll make it so and push.  Thanks for reviewing!

Fuzzing with Claude, I ran into an assertion failure that comes from
commit 2ebf25e7d:

create table t1 (a int, b int, c int);
create table t2 (a int primary key, b int, c int);

select j.x from (t1 s(x) left join t2 on s.x = t2.a) j;
server closed the connection unexpectedly

TRAP: failed Assert("context->new_index != INVALID_VAR")

This is because that since the join has an alias, j.x is a Var with
varno pointing to s and varnosyn pointing to the join.  When the join
is removed, ChangeVarNodes() notices that varnosyn still references
the join's RT index, so the Assert fires.

I think this varnosyn is fine to keep.  The join is only removed from
the jointree; its RTE stays in the rangetable through to the final
plan, so varnosyn still names a valid RTE.  And join removal didn't
touch varnosyn before 2ebf25e7d either.

Attached is a fix.

- Richard

Attachment

pgsql-hackers by date:

Previous
From: shihao zhong
Date:
Subject: Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Next
From: Paul A Jungwirth
Date:
Subject: Re: Add TG_* vars for FOR PORTION OF