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.94.2) (envelope-from ) id 1tlc57-000ZJk-Ga for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Feb 2025 23:05:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tlc55-000WC3-Gc for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Feb 2025 23:05:15 +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.94.2) (envelope-from ) id 1tlc55-000W5U-26 for pgsql-bugs@lists.postgresql.org; Fri, 21 Feb 2025 23:05:15 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tlc50-0002iw-1x for pgsql-bugs@lists.postgresql.org; Fri, 21 Feb 2025 23:05:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2025010100; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description; bh=fzrK9MXO+eQlH2vRTdi6oF4LxhjOqd5KwUCnBmJQafI=; b=miENozZ5Ec6pOQnZoX1UeeKqN9 qDgfzdf7lVI5tR2jOqS1CKKcIwwx8VlWZzdD4dfzhBPxCuae0xidY7StkCDLvTae0hQuWAQ9T8KT5 nXxFpW8M6gQwgoZMMklQVJlHVoo4pVxjdJoaw27vABXYTuc1NjERwJZvjShE7VPJ3K5KvzKXlNiul hqj89ERmqxxzc1bT3PvpYkPYny7zfOPY9igrCC76xRz8OTrVMfMPk9Wk8bCmIG71vA0+7iggHnwla K3nRVTd9KO+wFJekEUHQXDa1FJLx9ewpd58Bu2juOizEi8eksNDrvs2BDZCBBCAxI4laV+0+7EDmh 1Yz/uVHA==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1tlc50-008o3l-26; Fri, 21 Feb 2025 18:05:10 -0500 Date: Fri, 21 Feb 2025 18:05:10 -0500 From: Bruce Momjian To: Ronald Cruz Cc: pgsql-bugs@lists.postgresql.org, 'Peter Ford' , "Aaron J. Garcia" Subject: Re: Query result differences between PostgreSQL 17 vs 16 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Feb 21, 2025 at 11:13:17AM -0500, Ronald Cruz wrote: > Hi, > > We have observed an issue after upgrading to PostgreSQL 17 that caused us to > roll back to 16. Some of our queries are returning what I believe to be > erroneous results. > > I've attached two files here that can be used to reproduce what I'm seeing: > > schema_plus_data.sql - This contains a pg_dump of a reproducible test case with > a contrived schema and dataset of our use case. > > reproducer.sql - This isn't necessary, but perhaps you find it helpful. This is > a SQL script used to generate the schema and random data that hits this edge > case. It was used to generate the previous file and it has reliably hit the > issue so far from the handful of times I've tried. > > The query I'm observing issues for is the following: > > SELECT * FROM rc1 >     LEFT JOIN rc2 ON rc2.rc1_reference = rc1.description >     LEFT JOIN rc3 ON rc2.id = rc3.rc2_reference >     LEFT JOIN LATERAL rc_select(rc3.id) ON rc3.id IS NOT NULL; > > Under PostgreSQL 17, I'm seeing ~400k results returned, whereas in PostgreSQL > 16, I see ~6k. The results I believe to be erroneous are those that have 'BUG > HIT' in the output for PostgreSQL 17. These are results joined from rc_select > where rc3.id is null. I'm not expecting to see any of these rows as is the case > in PostgreSQL 16 output (and 15 as well from prior experience). > > I've observed this behavior in the latest PostgreSQL 17.4 but have also > encountered this in 17.2 and 17.3. The OS being used is RHEL 9.5 (plow). Please > let me know if you need any more information. We have a known problem with composite types and NULL constraints in PG 17 that I think we are fixing in PG 18. I saw IS NOT NULL in your query so I thought I would mention it: https://www.postgresql.org/message-id/Z37p0paENWWUarj-%40momjian.us We do have several NULL optimizations in PG 17. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future.