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

simplifyCoalesce of constant should match nullability

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.17.0
    • Fix Version/s: None
    • Component/s: core

      Description

      After CALCITE-2227, we will not replace Coalesce to Case When for natural join, when we use ReduceExpressionRule for our plan for Coalesce with constant, the nullability will chage( from nullable to notnull), this will cause VolcanoPlanner to throw error.

      Should i fix this? or we should not use this rule in VolcanoPlanner?

      This is the error thrown sql :

      select * from lateral (select * from scott_emp) as e
          join (table scott_dept) using (deptno)
          where e.deptno = 10 

      The plan before ReduceExpressionRule:

      LogicalProject(deptno=[COALESCE($7, $8)], empno=[$0], ename=[$1], job=[$2], mgr=    [$3], hiredate=[$4], sal=[$5], comm=[$6], dname=[$9], loc=[$10])
      +- LogicalFilter(condition=[=($7, 10)])
      +- LogicalJoin(condition=[=($7, $8)], joinType=[inner])
      :- LogicalProject(empno=[$0], ename=[$1], job=[$2], mgr=[$3], hiredate=[$4], sal=[$5], comm=[$6], deptno=[$7])
      : +- LogicalTableScan(table=[[scott_emp]])
      +- LogicalProject(deptno=[$0], dname=[$1], loc=[$2])
      +- LogicalTableScan(table=[[scott_dept]])
      

      The plan after:

      LogicalProject(deptno=[10], empno=[$0], ename=[$1], job=[$2], mgr=[$3], hiredate=[$4], sal=[$5], comm=[$6], dname=[$9], loc=[$10])
      +- LogicalFilter(condition=[=($7, 10)])
      +- LogicalJoin(condition=[=($7, $8)], joinType=[inner])
      :- LogicalProject(empno=[$0], ename=[$1], job=[$2], mgr=[$3], hiredate=[$4], sal=[$5], comm=[$6], deptno=[$7])
      : +- LogicalTableScan(table=[[scott_emp]])
      +- LogicalProject(deptno=[$0], dname=[$1], loc=[$2])
      +- LogicalTableScan(table=[[scott_dept]])
      

      We can see that the deptno's nullability changes from nullable to not null. And we encounter an type error when using ReduceExpressionRule in VolcanoPlanner.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                danny0405 Danny Chan
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m