Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.38.0
Description
Currently IN operator would not distinct values.
for example in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1) transform to in (1,2,3) is better, but currently would be in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1) without distinct.
Like case follow:
test case:
@Test void testReduceExpressionsWithIn() { final String sql = "select deptno, sal " + "from emp " + "where deptno in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1) "; sql(sql).withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS) .check(); }
plan would be:
LogicalProject(DEPTNO=[$7], SAL=[$5]) LogicalFilter(condition=[IN($7, { LogicalValues(tuples=[[ { 1 } , { 1 }, { 2 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 3 }, { 1 }]]) })]) LogicalTableScan(table=[[CATALOG, SALES, EMP]])
we should distinct Values and consider a more generic and simple way we can add a AggregateValueReduceRule to distinct Values
which plan should convert to:
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalValues(tuples=[[{ 1 }, { 3 }]])