iwanttobepowerful commented on PR #4614:
URL: https://github.com/apache/calcite/pull/4614#issuecomment-3489838221

   for sql:
   ```sql
   SELECT deptno, (SELECT CASE WHEN SUM(sal) > 10 then 'VIP' else 'Regular' END 
expr
                      FROM emp e
                      WHERE d.deptno = e.deptno) a
   FROM dept d;
   ```
   spark catalyst plan:
   ```
   == Optimized Logical Plan ==
   Project [deptno#575, if (isnull(alwaysTrue#621)) Regular else expr#613 AS 
a#615]     // <-------here is diff
   +- Join LeftOuter, (deptno#575 = deptno#586)
      :- Project [deptno#575]
      :  +- Relation spark_catalog.default.dept[deptno#575,dname#576,loc#577] 
parquet
      +- Aggregate [deptno#586], [CASE WHEN (sum(sal#584) > 10.0) THEN VIP ELSE 
Regular END AS expr#613, deptno#586, true AS alwaysTrue#621]      // 
<-------here is diff
         +- Project [sal#584, deptno#586]
            +- Filter isnotnull(deptno#586)
               +- Relation 
spark_catalog.default.emp[empno#578,ename#579,job#580,age#581,mgr#582,hiredate#583,sal#584,comm#585,deptno#586,email#587,create_datetime#588,upsert_time#589]
 parquet
   ```
   
   but this pr plan:
   ```
   LogicalProject(DEPTNO=[$0], A=[$3]), id = 56     // <-------here is diff
     LogicalJoin(condition=[=($0, $4)], joinType=[left]), id = 55
       LogicalTableScan(table=[[scott, DEPT]]), id = 11
       LogicalProject(EXPR=[CASE(>($1, 10.00), 'VIP':VARCHAR(7), 
'Regular':VARCHAR(7))], DEPTNO=[$0]), id = 54      // <-------here is diff
         LogicalAggregate(group=[{0}], agg#0=[SUM($1)]), id = 53
           LogicalProject(DEPTNO=[$7], SAL=[$5]), id = 52
             LogicalFilter(condition=[IS NOT NULL($7)]), id = 50
               LogicalTableScan(table=[[scott, EMP]]), id = 12
   ```
   
   so maybe we should write some extra code to fix 'fast' path (i.e. no use 
extra left join)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to