Richard Guo <[email protected]> 于2026年9月1日周二 15:43写道:
>
> I was studying the PHV bug caused by join-removal and ran into an
> assertion failure with the query below, which is not related to
> join-removal.  So start a new thread for it.
>
> create table ta (id int primary key, x int);
> create table tb (id int primary key, a_id int, x int);
> create table tc (id int, x int);
>
> explain (costs off)
> select 1 from ta t1 left join
>   (select tb.x as bx, 1 as one from ta a2 left join tb on a2.id =
> tb.a_id) t2 on true
>   left join lateral (select tc.x as cnt from tc where tc.id = t2.one
> offset 0) t3
>     on t2.bx = t3.cnt;
>
> TRAP: failed Assert("!have_unsafe_outer_join_ref(root, outerrelids,
> inner_paramrels)")
>

I tested v1 and it fixes the reported assertion failure.

I also noticed that the resulting plan contains a duplicated filter:
                            QUERY PLAN
-------------------------------------------------------------------
 Nested Loop Left Join
   ->  Seq Scan on ta t1
   ->  Materialize
         ->  Nested Loop Left Join
               ->  Hash Right Join
                     Hash Cond: (tb.a_id = a2.id)
                     ->  Seq Scan on tb
                     ->  Hash
                           ->  Seq Scan on ta a2
               ->  Subquery Scan on t3
                     Filter: ((tb.x = t3.cnt) AND (tb.x = t3.cnt))
                     ->  Seq Scan on tc
                           Filter: (id = (1))

```
Filter: ((tb.x = t3.cnt) AND (tb.x = t3.cnt))
```

This is not introduced by v1; I can reproduce the same duplicate qual on
pg16.14 as well, so it seems to be a pre-existing issue.

It is probably unrelated to this fix, but I thought it was worth mentioning
since the test case exposes it.


-- 
Thanks,
Tender Wang


Reply via email to