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

Mihai Budiu commented on CALCITE-7196:
--------------------------------------

We have an example of a query which cannot be decorrelated because of the 
Unnest (I commented about this in 
https://issues.apache.org/jira/browse/CALCITE-7031?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18022304#comment-18022304),
 but it can be decorrelated after this rewrite:

{code:sql}
create table t1(arr STRING ARRAY);
create table t2 (id string);
                
WITH ids AS (
  SELECT array_element.id
  FROM t1, UNNEST(t1.arr) AS array_element(id)
)
SELECT * FROM ids
WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.id = ids.id)
{code}

> Create an optimization pass which can convert some cases of Correlate + 
> Unnest to Unnest
> ----------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7196
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7196
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>    Affects Versions: 1.40.0
>            Reporter: Mihai Budiu
>            Assignee: Mihai Budiu
>            Priority: Minor
>
> Today UNNEST is always compiled into a Correlate + Unnest.
> Some query plans of this shape can be simplified however:
> {code}
> Project
>    Correlate
>       LeftInput
>       Uncollect
>          Project(correlatedVariable) // only one field here
>            Values
> {code}
> If the Project only preserves fields from the right-side of the Correlate, 
> such plans can be rewritten as 
> {code}
> Project
>    Uncollect
>      LeftInput
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to