Query result differences between PostgreSQL 17 vs 16

From: Ronald Cruz <cruz(at)rentec(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 'Peter Ford' <pford(at)rentec(dot)com>, "Aaron J(dot) Garcia" <agarcia(at)rentec(dot)com>
Subject: Query result differences between PostgreSQL 17 vs 16
Date: 2025-02-21 16:13:17
Message-ID: f5320d3d-77af-4ce8-b9c3-4715ff33f213@rentec.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.

Thank you in advance for any help,
Ron

Attachment Content-Type Size
reproducer.sql application/sql 2.5 KB
schema_plus_data.sql application/sql 126.7 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Laurenz Albe 2025-02-21 16:23:24 Re: Major Version Upgrade failure due to orphan roles entries in catalog
Previous Message Tom Lane 2025-02-21 14:41:43 Re: Major Version Upgrade failure due to orphan roles entries in catalog