Re: BUG #17978: Unexpected error: "wrong varnullingrels (b) (expected (b 5)) for Var 6/2" triggered by JOIN
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org
Date: 2023-06-19T10:21:43Z
Lists: pgsql-bugs
On Sun, Jun 18, 2023 at 3:57 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Temporarily disabling the setrefs.c crosscheck shows that it's
> trying to create this plan:
>
> which is the wrong join order: the filter condition can't be
> applied at that join level. So the nullingrel cross-check
> has caught a real bug, but why the bug?
FWIW, I found that we have an existing test query in sql/join.sql that
almost exposes this issue.
explain (costs off)
select * from int4_tbl t1
left join ((select t2.f1 from int4_tbl t2
left join int4_tbl t3 on t2.f1 > 0
where t3.f1 is null) s
left join tenk1 t4 on s.f1 > 1)
on s.f1 = t1.f1;
If we change the WHERE clause to 't2.f1 != coalesce(t3.f1, 1)', we will
see this issue.
explain (costs off)
select * from int4_tbl t1
left join ((select t2.f1 from int4_tbl t2
left join int4_tbl t3 on t2.f1 > 0
where t2.f1 != coalesce(t3.f1, 1)) s
left join tenk1 t4 on s.f1 > 1)
on s.f1 = t1.f1;
ERROR: wrong varnullingrels (b) (expected (b 5)) for Var 6/1
Thanks
Richard
Commits
-
Fix another cause of "wrong varnullingrels" planner failures.
- 3af87736bf5d 16.0 landed
-
doc: PG 16 relnotes, fix PREPARE/EXECUTE wording
- 3f1aaaa18068 16.0 cited