You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2017/07/06 23:18:00 UTC

[jira] [Resolved] (CALCITE-1799) "OR ... IN" sub-query conversion is wrong

     [ https://issues.apache.org/jira/browse/CALCITE-1799?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde resolved CALCITE-1799.
----------------------------------
       Resolution: Fixed
    Fix Version/s: 1.14.0

I'm a glass-half-full guy, so I think it's fair to say this is fixed. CALCITE-816 (RexSubQuery) fixed it. The fix only takes effect if you have {{expand = false}}, i.e. convert sub-queries to RexSubQuery nodes that are then handled by {{SubQueryRemoveRule}}.

If you are still running into this issue, make sure to set {{expand = false}}. If you're using {{Planner}}, you might need to use the APIs that [~gian] added in CALCITE-1874.

In http://git-wip-us.apache.org/repos/asf/calcite/commit/c12e37d4 I have added a test-case.

> "OR ... IN" sub-query conversion is wrong
> -----------------------------------------
>
>                 Key: CALCITE-1799
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1799
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.12.0
>            Reporter: Gian Merlino
>            Assignee: Julian Hyde
>              Labels: sub-query
>             Fix For: 1.14.0
>
>
> This query:
> {code}
> select * from emp where deptno = 10 or deptno in (
>     select dept.deptno from dept where deptno < 5)
> {code}
> Is converted to this by SqlToRelConverter:
> {code}
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>   LogicalFilter(condition=[OR(=($7, 10), true)])
>     LogicalJoin(condition=[=($7, $9)], joinType=[inner])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>       LogicalAggregate(group=[{0}])
>         LogicalProject(DEPTNO=[$0])
>           LogicalFilter(condition=[<($0, 5)])
>             LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> {code}
> But that's not right. {code}LogicalFilter(condition=[OR(=($7, 10), true)]){code} is always true and is in the wrong place anyway (it's applied after the inner join, where all the deptno = 10 records have already been removed).



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)