iwanttobepowerful commented on code in PR #4328:
URL: https://github.com/apache/calcite/pull/4328#discussion_r2084642017
##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -910,6 +910,24 @@ private static void matchJoin(SubQueryRemoveRule rule,
RelOptRuleCall call) {
int nFieldsLeft = join.getLeft().getRowType().getFieldCount();
int nFieldsRight = join.getRight().getRowType().getFieldCount();
+ // Correlation columns should also be considered.
+ // For example:
+ // LogicalJoin
+ // left right
+ // | |
+ // LogicalProject.NONE.[0, 1]
LogicalValues.NONE.[0]
+ // RecordType(INTEGER DEPTNO, CHAR(11) DNAME)
RecordType(INTEGER DEPTNO)
+ //
+ // and subquery: $SCALAR_QUERY with correlate
+ // LogicalProject(DEPTNO=[$1])
+ // LogicalFilter(condition=[=(CAST($0):CHAR(11) NOT NULL, $cor0.DNAME)])
+ //
+ // In such a case $cor0.DNAME need to be accounted as input form left side.
Review Comment:
use the plan after subquery removed like following, maybe more easier to
read?
```
SELECT t1.deptno FROM dept AS t0 JOIN emp AS t1 ON
(t1.deptno = (SELECT inner_t1.deptno FROM emp AS inner_t1 WHERE
inner_t1.ENAME = t0.DNAME));
LogicalProject(DEPTNO=[$11]), id = 794
LogicalJoin(condition=[=($11, $SCALAR_QUERY({
LogicalProject(DEPTNO=[$8])
LogicalFilter(condition=[=($1, $cor0.dname)])
LogicalTableScan(table=[emp])
}))], joinType=[inner]), id = 792
LogicalTableScan(table=[dept]), id = 784
LogicalTableScan(table=[emp]), id = 786
```
--
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]