Details
-
Improvement
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
None
-
None
Description
The Correlate is not currently supported when metadata gets the column origin.(RelMdColumnOrigins#getColumnOrigins)
If a column is processed from a correlation variable, the correlation variable is ignored and the rest of the columns are returned.
In fact, we should return null for cases that cannot be determined.
@Test void testColumnOriginsForCorrelate() { final String sql = "select (select max(dept.name || '_' || emp.ename)" + "from dept where emp.deptno = dept.deptno) from emp"; final RelMetadataFixture fixture = sql(sql); final HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE); final HepPlanner planner = new HepPlanner(programBuilder.build()); planner.setRoot(fixture.toRel()); final RelNode optimizedRel = planner.findBestExp(); fixture.withRelTransform(a -> optimizedRel.getInput(0).getInput(1)) .assertColumnOriginSingle("DEPT", "NAME", true); }
OptimizeRel:
LogicalProject(EXPR$0=[$9])
LogicalCorrelate(correlation=[$cor1], joinType=[left], requiredColumns=[{1, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject($f0=[||(||($1, '_'), $cor1.ENAME)])
LogicalFilter(condition=[=($cor1.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])