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

Optimize the IN sub-query and SOME sub-query by Metadata RowCount

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.39.0
    • None

    Description

      As same as the UNIQUE sub-query, before we convert the sub-query to RelNode. we use the Metadata to optimize it.

      • IN sub-query, If the sub-query is guaranteed to produce no row, just return FALSE.
      • SOME sub-query, If the sub-query is guaranteed to produce no row, just return FALSE.

      SQL Example:

      select * from dept as d where deptno not in (select count(*) from emp e having false)
      Before this PR:
      LogicalProject(DEPTNO=[$0], NAME=[$1])
        LogicalProject(DEPTNO=[$0], NAME=[$1])
          LogicalFilter(condition=[OR(=($2, 0), AND(IS NULL($5), >=($3, $2)))])
            LogicalJoin(condition=[=(CAST($0):BIGINT NOT NULL, $4)], joinType=[left])
              LogicalJoin(condition=[true], joinType=[inner])\n          
                LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
                LogicalProject(c=[$0], ck=[$0])
                  LogicalAggregate(group=[{}], c=[COUNT()])
                    LogicalValues(tuples=[[]])
              LogicalProject(EXPR$0=[$0], i=[true])
                LogicalValues(tuples=[[]])\n
      After this PR:
      LogicalProject(DEPTNO=[$0], NAME=[$1])
        LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) 

      Attachments

        Issue Links

          Activity

            People

              nobigo xiong duan
              nobigo xiong duan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: