Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wEeR8-004FaZ-0Z for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 02:32:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEeR6-000GIV-2S for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 02:32:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wEeR6-000GIN-1d for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 02:32:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wEeR0-000000023ve-3WLc for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 02:32:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 63K2WOuJ088900; Sun, 19 Apr 2026 22:32:24 -0400 From: Tom Lane To: Richard Guo cc: francois.jehl@pigment.com, pgsql-bugs@lists.postgresql.org, Robert Haas Subject: Re: BUG #19460: FULL JOIN rewriting issue on empty queries In-reply-to: References: <19460-5625143cef66012f@postgresql.org> <53936.1776633020@sss.pgh.pa.us> <81857.1776648374@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Mon, 20 Apr 2026 11:17:47 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <88898.1776652344.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 19 Apr 2026 22:32:24 -0400 Message-ID: <88899.1776652344@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Mon, Apr 20, 2026 at 10:26 AM Tom Lane 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. Hmm. The bug also goes away if "t" doesn't have a unique/pkey constraint, and I find that easy to understand: we can't apply outer join removal unless rel_supports_distinctness/rel_is_distinct_for succeed, so that this buggy code in remove_rel_from_restrictinfo is not reached. But that logic doesn't consider WHERE constraints AFAICS. So I think there is some other code path involved. It might turn out to not be all that interesting to run this to ground, but I want to do so because it might inform our estimate of the patch's blast radius. regards, tom lane