Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2857

Complicated plan generated for subuqery with both equi and non-equi condition

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • core

    Description

      SemiJoin extends Join directly instead of EquiJoin to support non-equi condition,
      e.g.

      select * from (select * from dept where dept.deptno in (select emp.deptno from emp where emp.job <> dept.name))R where R.deptno <= 10
      

      Currently, this query will be converted to

      SemiJoin(condition=[AND(=($1, $3), =($0, $2))], joinType=[inner])
        LogicalFilter(condition=[<=($0, 10)])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
        LogicalProject(DEPTNO=[$7], NAME=[$9])
          LogicalJoin(condition=[<>($2, $9)], joinType=[inner])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
            LogicalAggregate(group=[{0}])
              LogicalProject(NAME=[$1])
                LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      

      however the following plan is more efficient than the above one:

      LogicalProject(DEPTNO=[$0], NAME=[$1])
        LogicalFilter(condition=[<=($0, 10)])
          SemiJoin(condition=[=AND(=($0, $3), <>($1, $2))], joinType=[inner])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
            LogicalProject(JOB=[$2], DEPTNO=[$7])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            godfreyhe godfrey he

            Dates

              Created:
              Updated:

              Slack

                Issue deployment