kgyrtkirk commented on code in PR #4077:
URL: https://github.com/apache/calcite/pull/4077#discussion_r1871622890


##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -481,7 +481,7 @@ EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}])
   EnumerableCorrelate(correlation=[$cor0], joinType=[inner], 
requiredColumns=[{0}])
     EnumerableValues(tuples=[[{ 1, 2 }]])
     EnumerableAggregate(group=[{0}])
-      EnumerableCalc(expr#0..7=[{inputs}], expr#8=[true], 
expr#9=[CAST($t7):INTEGER], expr#10=[$cor0], expr#11=[$t10.A], expr#12=[=($t9, 
$t11)], i=[$t8], $condition=[$t12])
+      EnumerableCalc(expr#0..7=[{inputs}], expr#8=[true], 
expr#9=[CAST($t7):INTEGER], expr#10=[$cor0], expr#11=[$t10.EXPR$0], 
expr#12=[=($t9, $t11)], i=[$t8], $condition=[$t12])

Review Comment:
   Actually both of them are misleading; there is no `A` in either plans...due 
to the fact that `RexInputRef` accesses column by idx not by name - it has no 
real effect
   
   ### for the 1st case the following happens:
   
   <details>
   <summary>RelFieldTrimmer match</summary>
   
   matches on the plan:
   ```
   LogicalCorrelate(correlation=[$cor0], joinType=[inner], 
requiredColumns=[{0}])
     LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
       LogicalValues(tuples=[[{ 1, 2 }]])
     LogicalAggregate(group=[{0}])
       LogicalProject(i=[true])
         LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7])
           LogicalFilter(condition=[=($8, $cor0.A)])
             LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], DEPTNO0=[CAST($7):INTEGER])
               LogicalTableScan(table=[[scott, EMP]])
   ```
   * left is left intact
   * the right is trimmed from:
   ```
   LogicalAggregate(group=[{0}])
     LogicalProject(i=[true])
       LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7])
         LogicalFilter(condition=[=($8, $cor0.A)])
           LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], DEPTNO0=[CAST($7):INTEGER])
             LogicalTableScan(table=[[scott, EMP]])
   
   ```
   to:
   ```
   LogicalAggregate(group=[{0}])
     LogicalProject(i=[true])
       LogicalFilter(condition=[=($1, $cor0.A)])
         LogicalProject(EMPNO=[$0], DEPTNO0=[CAST($7):INTEGER])
           LogicalTableScan(table=[[scott, EMP]])
   ```
   * trim is executed
   * the rowType used for left is `RecordType(INTEGER EXPR$0, INTEGER EXPR$1)` 
(as it has the Project at this point)
   * during the rewrite: a `RexFieldAccess` is created to reference column `0`
   </details>
   
   <details>
   <summary>ProjectRemoveRule fires</summary>
   
   the project of:
   ```
   LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
     LogicalValues(subset=[rel#99:RelSubset#0.NONE.[]], tuples=[[{ 1, 2 }]])
   ```
   Is identified as 
[isTrivial](https://github.com/apache/calcite/blob/0eb83b1dc6316cba73c2c49e8fbccfa390333fbe/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java#L82)
   
   The project is removed.
   </details>
   
   
   ### in the other case:
   
   <details>
   <summary>RelFieldTrimmer matches on a different plan</summary>
   
   ```
   LogicalCorrelate(correlation=[$cor0], joinType=[inner], 
requiredColumns=[{0}])
     LogicalProject(A=[$0], B=[$1])
       LogicalValues(tuples=[[{ 1, 2 }]])
     LogicalAggregate(group=[{0}])
       LogicalProject(i=[true])
         LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7])
           LogicalFilter(condition=[=($8, $cor0.A)])
             LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], DEPTNO0=[CAST($7):INTEGER])
               LogicalTableScan(table=[[scott, EMP]])
   ```
   
   * which has `LogicalProject(A=[$0], B=[$1])` ; so the rowtype for left is 
`RecordType(INTEGER A, INTEGER B)`
   * similar transform happens ; but rowType has `A` in it.
   
   </details>
   <details>
   <summary>ProjectRemoveRule fires</summary>
   
   the project of:
   ```
   LogicalProject(A=[$0], B=[$1])
     LogicalValues(subset=[rel#100:RelSubset#0.NONE.[]], tuples=[[{ 1, 2 }]])
   ```
   Is identified as 
[isTrivial](https://github.com/apache/calcite/blob/0eb83b1dc6316cba73c2c49e8fbccfa390333fbe/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java#L82)
   
   The project is removed.
   </details>
   



-- 
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