Re: BUG #19460: FULL JOIN rewriting issue on empty queries
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: francois.jehl@pigment.com, pgsql-bugs@lists.postgresql.org, Robert Haas <robertmhaas@gmail.com>
Date: 2026-04-20T02:17:47Z
Lists: pgsql-bugs
On Mon, Apr 20, 2026 at 10:26 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Thanks for looking at it! There is a loose end still bothering me: > if you remove the lower "WHERE t.id = ..." clause, or change it to be > something other than an equality constraint on t.id, the bug doesn't > manifest. The reason for that is un-obvious. The reason seems to be that the equality constraint is a restriction clause for the inner relation 't', and is needed to determine that the relation has a matching unique index and is therefore distinct. If we remove it, or change it to something that isn't mergejoinable, we won't be able to prove the inner side of the left join is distinct, and thus won't be able to remove that left join. I think the qual clause "sub.id = empty_source.id" might be confusing, because empty_source.id is constant NULL, and this clause would be simplified to constant NULL during const-folding. - Richard
Commits
-
Fix relid-set clobber during join removal.
- f0ac6d494b56 19 (unreleased) landed
- 798dabe83887 16.14 landed
- 53cb4ec1ded7 17.10 landed
-
Clean up all relid fields of RestrictInfos during join removal.
- d509be4ace90 16.14 landed
- cfcd5711160a 19 (unreleased) landed
- 766d40286600 17.10 landed
- 16fb94605c8f 18.4 landed