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 1vsJJx-00Fwi2-2G for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 11:32:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsJJw-009y7n-1o for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 11:32:48 +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 1vsJ7h-009rWw-1F for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 11:20:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsJ7e-00000001BY4-3H6t for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 11:20:09 +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=0UlnZqdYeGFvyxFnfY+cyjauTG0eCtNLy7KCV/N2Sy0=; b=sZlWIFnWEIDjwVmKgLYTzOGOJg PzZMEn7DXjt+BtAsWJz9wpntYY4mRAff1/gfFHTscVFPJUimG0i57hHtuTSwgceQT3XDCK8PkaoW7 SAWhByuO8wGIS2gZJfXkB4gCyqHBYvpqT3Y49lSIFMI2si4FwoVl1BuC24utndIBMQXQurRSwLaXA omXFJtT/6bAnzNRitv2Fy5tMWdcpMdJP5VI5SxuxRPK8cmALaIJrESOf8FtXDbUmrzdXg0ozvC9qz tNnKLDI7m/BbuQWE4TakTCd79NE2oJPfpOjtWhoEc59BS2GmOfsSeY1b1jRR+XMdmd1arMwprBady ycYHNHAA==; 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.96) (envelope-from ) id 1vsJ7c-003QQR-1n for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 11:20:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsJ7a-003Elm-2m for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 11:20:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19412: Wrong query result with not null constraint To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: s.shinderuk@postgrespro.ru Reply-To: s.shinderuk@postgrespro.ru, pgsql-bugs@lists.postgresql.org Date: Tue, 17 Feb 2026 11:19:36 +0000 Message-ID: <19412-1d0318089b86859e@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: 19412 Logged by: Sergey Shinderuk Email address: s.shinderuk@postgrespro.ru PostgreSQL version: 17.8 Operating system: Ubuntu 24.04 Description: =20 Using this script (repro.sql): drop table if exists a, x, y; create table a (id int, x_id int, y_id int); insert into a values (1, 1, 1), (1, 2, 2), (1, 3, 3); create table x (id int, nm text, constraint pk_x_id primary key (id)); insert into x values (1, 'x1'), (2, 'x2'), (3, 'x3'); create table y (id int, nm text, constraint pk_y_id primary key (id)); insert into y values (1, 'y1'), (3, 'y3'), (4, 'y4'); select a.id, z.id from a join x on x.id =3D a.x_id left join y on y.id =3D a.y_id join lateral(select x.id union all select y.id) z on z.id is not null; alter table y drop constraint pk_y_id; alter table y alter column id drop not null; select a.id, z.id from a join x on x.id =3D a.x_id left join y on y.id =3D a.y_id join lateral(select x.id union all select y.id) z on z.id is not null; on PostgreSQL 17.8 I get: postgres=3D# \i repro.sql DROP TABLE CREATE TABLE INSERT 0 3 CREATE TABLE INSERT 0 3 CREATE TABLE INSERT 0 3 id | id ----+---- 1 | 1 1 | 1 1 | 2 1 | 1 | 3 1 | 3 (6 rows) ALTER TABLE ALTER TABLE id | id ----+---- 1 | 1 1 | 1 1 | 2 1 | 3 1 | 3 (5 rows) Something seems to be wrong with IS NOT NULL optimization. v18 and master show the same, v16 is fine.