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 1wEejI-004Fv7-1S for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 02:51:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEejG-000Iew-1N for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 02:51:18 +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 1wEejG-000Ien-0G for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 02:51:18 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wEejD-0000000242E-42hh for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 02:51:17 +0000 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-4670676ba03so528076b6e.1 for ; Sun, 19 Apr 2026 19:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776653474; cv=none; d=google.com; s=arc-20240605; b=LEJ1n4YctBXT8R7pQZt1Jz+qYd8PqDm3mUcytGKZxBh5aCYeFOs/2SWPxR7c7+4HV8 BXTMjPy6XK3PHIaJU708GimyZrnF0KSq+KNRkQNhgTqPHQJyi2d9bHym/YwnQl6FUgPH eqUY5YFZxSi8LqxUwjnDBpt1+uUvvkdcO9M8tWojxXSpOLCXEA8N/lkaGDYoMD9irGA3 FjZec8CMGxr+7MgMeKXAfRcZYBYWGI/6OnIyZF12TvhITk/iGWUbIp2uwBEwQqQLb3LH xQczOSqi0JCZ9m/caC25TED0WIlu2PEdE0y/FtmUVAonQDpaNl/TeVjgXyBjtzpHuSij uHMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RjjUN3rVIE/tI9DtD9F8Ldg2h0FIR3Aiw9G94FctlgU=; fh=jDoRtkvly/JFkSCn0DJ+ahy3SozlquHvDlylAEnFYIw=; b=jZMJBjWo20q+JzFgP6EKnjYE/cXh7ZwppZ132t4+rk06isrj7sEnwNdTHmuiISyyQS JLK/zrkf9NC46YVw0nNzt3o0YCINVHLNBYIdX2YzhP1H1SCZEWyk9i5YQu+Gu0OPlBEU wS9B5aSWCp2Z4njYrZoKQZ+4GJnz3PslGzIgZIIp2EGBDbtboSEAw39JQZe2lx+lj4O3 IIEPfJWxjjWk4VmhwDuNrul7lYi83+nV44F+y2HldSWzJDbD6I7prIZ9RHVQ8ogoFP0u 51fmR5yTtSjFHTCdjJ9DHPYWvvTzRW+x1G6vnKgsCYSK3ggWPji6sNZBqt2Q3Pyq/OLe QVQw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776653474; x=1777258274; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RjjUN3rVIE/tI9DtD9F8Ldg2h0FIR3Aiw9G94FctlgU=; b=ZuRytvQWt2gM9JfEGLhIByXsJWtUQCmVWtjEOb+VZckYys7H3fGwnncrmUaboKm3TN A57MvMlRfrqRCA7VTnCfDxhmtEwzDSX+PftnWLvrkBy5shY1HQOc47CmTpBuplibZCuX HY4RMtfIXei5jDO+MMiV/+1OjkA1UM6o7w3xB0zrvKu18JFGMttSh2W+p5Dx5KELTmYC IVCFVU9RbI8ndJGTQtHZvykQ4k3aI5gv3Th81ZITuZ0/Mo5G/dlX3uFk2cQ/rCPzrv85 jatDMGQ7VfmXOjDVPlyxoNN1N0+zWeV9stSDvZjq0uNrKcitDSHbhOarzZwnsBArQEIx JE1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776653474; x=1777258274; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RjjUN3rVIE/tI9DtD9F8Ldg2h0FIR3Aiw9G94FctlgU=; b=ZfDr7GRAbhV239rv6Ko6NU6XOMBGUsNAvHHXDsxg5Lahtk5CCG0yGF24bLLwiC5i3T atPMSxo6u4YG/T0j+OrEMZ4E+yiClx7lqYJa2Mhhtota5BiUObHS2A+2EeXVorA1iT4X 9FxOWSu34GiT/qksmFUfUQ2lsQCu6URJ7Hev2/cR4vzVisHtdbAmLxnFh4IAOI6ztIrC fFaZZL/C0fHXF5U+HIYr8TsQOhbMWzjMHAZQk/qmqV0Dw6Y4STA5OHEJTbI8HZBd4052 ND8UGRavQTLXghGk0oovNb4PG9ze+7wrwedE+jYAmhIY4a+2eckRAOEEkvbnK9wd+9xa q0wA== X-Forwarded-Encrypted: i=1; AFNElJ9FFY1jF98op7GmLcD4uLklQgyKzw8UbmyvZAGXgXdnSFsPDcr1yFm/Ze64Mc0CDOQw+72LNz5KrUoc@lists.postgresql.org X-Gm-Message-State: AOJu0YzwelP0wtx4e74h5aa+a47/GiSBoP+lUHrA6p1ZdZ5MvZ/yYPEJ y6oRcjSgy9ftfhgCf2K27a4Dj1FUpdlizv+wgbQP0B7rha4QBLVQ4equ/7xHAgcRbfvBEhLa5lW zZSDzTtIqq+RSy5828QMRBjnB4c6rI9s= X-Gm-Gg: AeBDietrnzSeFNk7ircI7TGMDKg/v33jd180tzPhiPWGBNB+L8ALv+oQpcyvnHWhm7B uuFW3rVqj4Ysf+jBMGcT0nhPR0FHjsqmFatTgO1OU3AEe5LiYlPUNF3daSifsV7/C9ubQUvnzdO h8oQq7kzGxBCFvewS1UynrX0u60zfFQL0TUjQwu2F/e5uidC6VCshrCEULvNI3EqNgtqfjl5VM9 GBi4jcTHYme1UVpV5W12UhHQaxhTIdaQXEGhU8QxHkrGc7n3rojzFgsEHFfG6e57pjf44xnF8uv gq+CxWj8jDK9TXFwKt0= X-Received: by 2002:a05:6808:159e:b0:475:be8e:e543 with SMTP id 5614622812f47-4799ca772femr7715476b6e.41.1776653473707; Sun, 19 Apr 2026 19:51:13 -0700 (PDT) MIME-Version: 1.0 References: <19460-5625143cef66012f@postgresql.org> <53936.1776633020@sss.pgh.pa.us> <81857.1776648374@sss.pgh.pa.us> <88899.1776652344@sss.pgh.pa.us> In-Reply-To: <88899.1776652344@sss.pgh.pa.us> From: Richard Guo Date: Mon, 20 Apr 2026 11:51:02 +0900 X-Gm-Features: AQROBzCbbM7oJo3ZV9fiGDGB_kvjvD97mAtFQEvOQv6RvAtgvYJZqA5H05dHTnA Message-ID: Subject: Re: BUG #19460: FULL JOIN rewriting issue on empty queries To: Tom Lane Cc: francois.jehl@pigment.com, pgsql-bugs@lists.postgresql.org, Robert Haas Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Apr 20, 2026 at 11:32=E2=80=AFAM Tom Lane wrote= : > Richard Guo writes: > > On Mon, Apr 20, 2026 at 10:26=E2=80=AFAM Tom Lane w= rote: > >> Thanks for looking at it! There is a loose end still bothering me: > >> if you remove the lower "WHERE t.id =3D ..." clause, or change it to b= e > >> 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. Hmm, relation_has_unique_index_for does consider the lower "WHERE t.id =3D ..." clause, as that clause is a restriction clause for "t", and relation_has_unique_index_for automatically adds any usable restriction clauses for the rel. - Richard