Mihai Budiu created CALCITE-7969:
------------------------------------

             Summary: Query with unnest of a column of the outer query cannot 
be decorrelated
                 Key: CALCITE-7969
                 URL: https://issues.apache.org/jira/browse/CALCITE-7969
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.42.0
            Reporter: Mihai Budiu


Neither of the two decorrelators can handle this query currently:
{code}
SELECT d.deptno,
  (SELECT COUNT(*) FROM UNNEST(d.a) AS u(x)) AS c
FROM (SELECT deptno,
        CASE WHEN deptno = 40 THEN NULL ELSE ARRAY[deptno, deptno * 2] END AS a
      FROM dept) AS d;
{code}

Proposed fix:

Since [CALCITE-7608], Uncollect can pass input fields through to its output. 
With this, the decorrelators can handle Uncollect like other single-input 
operators. The decorrelated Uncollect:

unnests the same collection fields as before (collectionFieldIndices, mapped 
through the input frame);
passes through its old pass-through fields (mapped) and the correlation columns 
of the input frame;
keeps isOuter and withOrdinality.
The new frame maps each correlation definition to its pass-through output 
column. For the first query, the expected plan has no Correlate: DEPT 
left-joined with an Aggregate grouped on A, over an Uncollect that passes A 
through, over the distinct values of A.

The same change is necessary in TopDownGeneralDecorrelator, as 
unnestInternal(Uncollect).





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

Reply via email to