[ 
https://issues.apache.org/jira/browse/CALCITE-7913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18136412#comment-18136412
 ] 

zzwqqq commented on CALCITE-7913:
---------------------------------

I reproduced [~mbudiu]’s example in CoreQuidemTest. This smaller example also 
fails with Correlation variable $cor0 should be defined:
{code:sql}
select r.p
from (values (1)) as t(x)
cross join lateral (select t.x + (select t.x) as p) as r;
{code}

>From debugging, the first decorrelation pass returns normally, but rewrites 
>only the direct reference and removes the outer Correlate. The reference 
>inside RexSubQuery.rel is left unbound. The exception occurs later during code 
>generation.


> LATERAL sub-query that references the outer query fails with "Unable to 
> implement"
> ----------------------------------------------------------------------------------
>
>                 Key: CALCITE-7913
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7913
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.42.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>
> If a LATERAL sub-query references a column of the outer query both directly 
> and inside a nested EXISTS, Calcite cannot implement the plan. This happens 
> with expand = false only. 
> h4. Reproduction
> {code:sql}
> !use scott
> !set outputformat mysql
> !set expand false
> select *
> from (values 2) as b (y),
>   lateral (select * from (values 3) as c (z)
>     where c.z > b.y
>     and exists (select 1 from (values 4) as d (w) where d.w > b.y)) as l;
> +---+---+
> | Y | Z |
> +---+---+
> | 2 | 3 |
> +---+---+
> (1 row)
> !ok
> {code}
> PostgreSQL 14 returns this row. Calcite fails:
> {noformat}
> java.lang.IllegalStateException: Unable to implement
> EnumerableCalc(expr#0=[{inputs}], expr#1=[2], expr#2=[3], expr#3=[4], 
> expr#4=[$cor0],
>     expr#5=[$t4.Y], expr#6=[>($t3, $t5)], Y=[$t1], Z=[$t2], $condition=[$t6])
>   EnumerableValues(tuples=[[{ 4 }]])
>       Suppressed: java.lang.NullPointerException: Cannot invoke
> "org.apache.calcite.adapter.enumerable.RexToLixTranslator$InputGetter.field(...)"
>  because "getter" is null
> {noformat}
> With assertions enabled, the error is "AssertionError: Correlation variable 
> $cor0 should be defined".
>  



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to