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.98.2) (envelope-from ) id 1xHeZr-00000003Drw-1tQL for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Oct 2026 09:50:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHeZp-0000000DfYD-0xw7 for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Oct 2026 09:50:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHabw-0000000CrcP-1F2j for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 05:36:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHabu-00000002HVV-2pNT for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 05:36:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=ky6biFyBaAA8bSQ6GG4Fef6Fo5LUk52B1ifk0USK7/I=; b=FTfxMmK6p6EyltJNLL73TL/BSs pesxDV/tPKjLNISIdV8T/C+8uyPmmZn3kcqV0BTSCq65iYVXLMifsszDHYkgXJ3PlXnpE91rgfoGT 756d2XEsdtqvGJyG66PgRxuPEEnDCdDf+SL3BRsG9ZBznGepkvDK3iyIGEbDkCnTocqxGaDjj+Emx EUUGDDmwmnJEEKHfGFMT1luge4ZiipBrv/vvImk4jSdDIPe03Gm1WkWDbHbQ/KIeDvTaSekiku4LM xFLNyobpWLKShGggsim/zLgdvlXbWrKDthUK5VwzBCBZzs0lAjU3p6hpcbe7Kzo2vQGIWkpa8KWSE co4kjZ4w==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHabs-00000006atg-2VNT for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 05:36:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHabr-00000002TpI-1I70 for pgsql-bugs@lists.postgresql.org; Fri, 16 Oct 2026 05:36:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19765: Wrong result from a chain of LEFT JOINs since v16 To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: leis@in.tum.de Reply-To: leis@in.tum.de, pgsql-bugs@lists.postgresql.org Date: Fri, 16 Oct 2026 05:35:05 +0000 Message-ID: <19765-5778b18918040583@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19765 Logged by: Viktor Leis Email address: leis@in.tum.de PostgreSQL version: 19rc1 Operating system: Ubuntu 26.04.1 Description: =20 Hi, The following self-contained query returns a wrong answer on every release since PostgreSQL 16 (verified on 16.0, 17.9, 18.6 and current master at 3c157ad1167; PostgreSQL 15.0 and 14.7 return the correct answer): select a.a, b.b, c.c, d.d from (values (1),(2)) as a(a) left join (values (1),(2)) as b(b) on a.a =3D b.b left join (values (7),(2)) as c(c) on b.b =3D c.c left join (values (1),(2)) as d(d) on c.c =3D d.d where a.a =3D 1; a | b | c | d ---+---+---+--- 1 | 1 | | 1 (1 row) c.c is correctly null-extended: b.b is 1 and c contains only 7 and 2, so the third join has no match. But then "c.c =3D d.d" is NULL =3D d.d, which= is never true, so d.d must be NULL as well: a | b | c | d ---+---+---+--- 1 | 1 | | (1 row) Ordinary tables behave the same way; the VALUES lists are only for brevity. EXPLAIN shows that all three join conditions have disappeared, leaving three unqualified nested-loop left joins: Nested Loop Left Join -> Values Scan on "*VALUES*" Filter: (column1 =3D 1) -> Nested Loop Left Join -> Nested Loop Left Join -> Values Scan on "*VALUES*_1" Filter: (column1 =3D 1) -> Values Scan on "*VALUES*_2" Filter: (column1 =3D 1) -> Values Scan on "*VALUES*_3" Filter: (column1 =3D 1) Best regards, Viktor Leis