Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs

Alexander Lakhin <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-05T04:00:00Z
Lists: pgsql-hackers
Hello David!

05.11.2025 00:55, David Rowley wrote:
> I finally decided that it was a bit too obscure a scenario to test to
> verify that the same silly mistake didn't reappear.
>
> Thanks again for the report and the simple recreation steps.

Thank you for the fix!

But while playing around, I've just discovered another interesting error:

SET enable_seqscan = 'off';
SELECT * FROM t EXCEPT SELECT * FROM t
UNION SELECT * FROM pt;

leads to:
ERROR:  XX000: no relation entry for relid 0
LOCATION:  find_base_rel, relnode.c:541

Best regards,
Alexander