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?