Re: BUG #18184: ERROR: wrong varnullingrels (b) (expected (b 3)) for Var 2/2 - Mailing list pgsql-bugs

From Richard Guo
Subject Re: BUG #18184: ERROR: wrong varnullingrels (b) (expected (b 3)) for Var 2/2
Date
Msg-id CAMbWs4-zNHy3GAjiK7vnTEpU8eWiFRtHUB9s5mpo1Edhs=0Dfw@mail.gmail.com
Whole thread Raw
In response to BUG #18184: ERROR: wrong varnullingrels (b) (expected (b 3)) for Var 2/2  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18184: ERROR: wrong varnullingrels (b) (expected (b 3)) for Var 2/2  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs

On Mon, Nov 6, 2023 at 10:39 PM PG Bug reporting form <noreply@postgresql.org> wrote:
Hi,
We found a bug in PostgreSQL 16. I have simplified the case:

SELECT
function1(table1)
FROM table2
LEFT JOIN table1 ON table1_id = table2_id
LEFT JOIN LATERAL (SELECT 1 FROM table3) AS tx3 ON (true)
LIMIT 5;

ERROR:  wrong varnullingrels (b) (expected (b 3)) for Var 2/2

Thanks for the report!  This is an error message that hasn't been seen
in a long time.

It seems that when we optimize field selection from a whole-row Var into
a simple Var while simplifying functions, we fail to propagate the
nullingrels into the new Var.

Attached is a hotfix for this error.  But I'm wondering if there are
other similar cases where we have mismatched nullingrels that we haven't
discovered yet.  Any thoughts?

Thanks
Richard
Attachment

pgsql-bugs by date:

Previous
From: David Rowley
Date:
Subject: Re: BUG #18177: certain queries under certain contexts take multiple orders of magnitude longer compared to v10
Next
From: Laurenz Albe
Date:
Subject: Re: BUG #18185: Error when calling whoami at the beginning of the installation