query.sql

application/sql

Filename: query.sql
Type: application/sql
Part: 1
Message: [BUG] Remove self joins causes 'variable not found in subplan target lists' error
explain (verbose, costs off)
select t1.j from t1
    left join t2 on t1.i = t2.i and t2.j = 1
    left join (
        select i from t3
        where exists (
            select true
                     from t4
                left join t5 as t5 on t5.j = t4.j
                left join t5 as t6 on t6.j = t4.j
            where t4.i = t3.i
              and t4.i = 2
        )
    ) t on t1.j = t.i;