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

Danny Chen edited comment on CALCITE-4206 at 9/1/20, 11:44 AM:
---------------------------------------------------------------

To fix this issue, i plan to add a protection when decorrelate the sort, like 
this

{code:java}
public Frame decorrelateRel(Sort rel) {
    // Can not decorrelate if the sort has per-correlate-key attributes like
    // offset or fetch limit, because these attributes scope would change to
    // global after decorrelation. They should take effect within the scope
    // of the correlation key actually.
    if (rel.offset != null || rel.fetch != null) {
      return null;
    }
{code}

A surprising result is test 
{{SqlToRelConverterTest.testExistsCorrelatedLimitDecorrelate}} was also fixed.


was (Author: danny0405):
To fix this issue, i plan to add a protection when decorrelate the sort, like 
this

{code:java}
public Frame decorrelateRel(Sort rel) {
    if (rel.offset != null || rel.fetch != null) {
      return null;
    }
{code}

A surprising result is test 
{{SqlToRelConverterTest.testExistsCorrelatedLimitDecorrelate}} was also fixed.

> RelDecorrelator outputs wong plan for correlate sort with fetch limit
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-4206
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4206
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.25.0
>            Reporter: Danny Chen
>            Assignee: Danny Chen
>            Priority: Major
>             Fix For: 1.26.0
>
>
> For query
> {code:sql}
> SELECT deptno, ename
>   FROM
>     (SELECT DISTINCT deptno FROM emp) t1,
>       LATERAL (
>         SELECT ename, sal
>         FROM emp
>         WHERE deptno = t1.deptno
>         ORDER BY sal
>         DESC LIMIT 3
>       )
> {code}
> The current plan after decorrelation is
> {code:xml}
> LogicalProject(DEPTNO=[$0], ENAME=[$1])
>   LogicalJoin(condition=[=($0, $3)], joinType=[inner])
>     LogicalAggregate(group=[{0}])
>       LogicalProject(DEPTNO=[$7])
>         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>     LogicalSort(sort0=[$1], dir0=[DESC], fetch=[3])
>       LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
>         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> which is wrong, because the partition sort(on sal) changes to global.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to