On Wed, 5 Nov 2025 at 17:00, Alexander Lakhin <[email protected]> wrote: > 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
:-( This happens because of the code I added to try to give better estimates to the number of groups when only a single child remains in the UNION. Because the only surviving Path is for the EXCEPT set-op, there are Vars with varno==0, which estimate_num_groups() does not like. I'm considering restricting that code Path to where the path->parent->reloptkind != RELOPT_UPPER_REL. It doesn't feel great adding the special case, but likely having better row estimates is worthwhile, when it's possible. I'll sit on that for a bit and see if I can think of a better way. (Yet another reason we should probably fix the varno==0 issue.) Thanks for the report and reproducer, again! David
