public inbox for [email protected]  
help / color / mirror / Atom feed
From: Richard Guo <[email protected]>
To: Markus Winand <[email protected]>
Cc: [email protected]
Subject: Re: ERROR: wrong varnullingrels (b 3) (expected (b)) for Var 2/1
Date: Wed, 31 May 2023 10:47:03 +0800
Message-ID: <CAMbWs49ANAiHiApMNamW7e6saiha3GVj81RdDEpEZaFO9Gzxqw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Tue, May 30, 2023 at 10:48 PM Markus Winand <[email protected]>
wrote:

> I found an error similar to others before ([1]) that is still persists as
> of head right now (0bcb3ca3b9).
>
> CREATE TABLE t (
>         n INTEGER
> );
>
> SELECT *
>   FROM (VALUES (1)) t(c)
>   LEFT JOIN t ljl1 ON true
>   LEFT JOIN LATERAL (WITH cte AS (SELECT * FROM t WHERE t.n = ljl1.n)
> SELECT * FROM cte) ljl2 ON ljl1.n = 1;
>
> ERROR:  wrong varnullingrels (b 3) (expected (b)) for Var 2/1
>
> Note that the error does **not** occur if the CTE is unwrapped like this:
>
> SELECT *
>   FROM (VALUES (1)) t(c)
>   LEFT JOIN t ljl1 ON true
>   LEFT JOIN LATERAL (SELECT * FROM t WHERE t.n = ljl1.n) ljl2 ON ljl1.n =
> 1;


Thanks for the report!  Reproduced here.  Also it can be reproduced with
subquery, as long as the subquery is not pulled up.

SELECT *
  FROM (VALUES (1)) t(c)
  LEFT JOIN t ljl1 ON true
  LEFT JOIN LATERAL (SELECT * FROM t WHERE t.n = ljl1.n offset 0) ljl2 ON
ljl1.n = 1;
ERROR:  wrong varnullingrels (b 3) (expected (b)) for Var 2/1

When we transform the first form of identity 3 to the second form, we've
converted Pb*c to Pbc in deconstruct_distribute_oj_quals.  But we
neglect to consider that rel C might be a RTE_SUBQUERY and contains
quals that have lateral references to B.  So the B vars in such quals
have wrong nulling bitmaps and we'd finally notice that when we do
fix_upper_expr for the NestLoopParam expressions.

Thanks
Richard


view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: ERROR: wrong varnullingrels (b 3) (expected (b)) for Var 2/1
  In-Reply-To: <CAMbWs49ANAiHiApMNamW7e6saiha3GVj81RdDEpEZaFO9Gzxqw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox