Re: Removed left join leaves its key in the outer rel's target list

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hi(at)joel(dot)id
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Removed left join leaves its key in the outer rel's target list
Date: 2026-11-29 17:30:26
Message-ID: 710572.1795973426@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

hi(at)joel(dot)id writes:
> On PostgreSQL 18.6, when a left join is removed because nothing reads its
> inner side, the outer relation's scan still emits the join key. Where that
> scan feeds another join, the dead column rides along: under a hash join it
> widens the hash table, which can make it spill.

I don't believe this is an issue anymore in 18.7, see 2ebf25e7d et al.
Your example now gives

Aggregate
Output: count(*)
-> Hash Join
Hash Cond: (q1.s = q2.s)
-> Seq Scan on pg_temp.q q1
Output: q1.s, q1.p, q1.base
-> Hash
Output: q2.s
-> Seq Scan on pg_temp.q q2
Output: q2.s

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2026-11-29 17:35:21 Re: BUG #19928: pg_upgrade fails on v18 schema with NOT NULL ... NO INHERIT and inheritance
Previous Message Tom Lane 2026-11-29 16:47:25 Re: btree_gist: <-> fails on same-sign infinite intervals