Skip to content

Commit 0e967d5

Browse files
committed
[CALCITE-7434] Error in new decorrelation algorithm caused by FilterJoinRule omitting variablesSet
1 parent d59c7f3 commit 0e967d5

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.calcite.tools.RelBuilderFactory;
3737

3838
import com.google.common.collect.ImmutableList;
39+
import com.google.common.collect.ImmutableSet;
3940
import com.google.common.collect.Sets;
4041

4142
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -249,6 +250,7 @@ protected void perform(RelOptRuleCall call, @Nullable Filter filter,
249250

250251
// create a FilterRel on top of the join if needed
251252
relBuilder.filter(
253+
filter == null ? ImmutableSet.of() : filter.getVariablesSet(),
252254
RexUtil.fixUp(rexBuilder, aboveFilters,
253255
RelOptUtil.getFieldTypeList(relBuilder.peek().getRowType())));
254256
call.transformTo(relBuilder.build());

core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5685,7 +5685,7 @@ LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
56855685
LogicalProject(DEPTNO=[$0])
56865686
LogicalFilter(condition=[=($0, $cor0.DEPTNO)])
56875687
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
5688-
}))])
5688+
}))], variablesSet=[[$cor0]])
56895689
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
56905690
LogicalFilter(condition=[>($0, 10)])
56915691
LogicalTableScan(table=[[CATALOG, SALES, EMP]])

core/src/test/resources/sql/new-decorr.iq

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,62 @@ EnumerableCalc(expr#0..3=[{inputs}], ENAME=[$t1], JOB=[$t2], SAL=[$t3])
401401
!plan
402402
!}
403403

404+
# [CALCITE-7434] Error in new decorrelation algorithm caused by FilterJoinRule omitting variablesSet
405+
SELECT E.EMPNO
406+
FROM EMP E
407+
JOIN DEPT D ON E.DEPTNO = D.DEPTNO
408+
WHERE E.EMPNO > 10 AND D.DEPTNO = (
409+
SELECT MIN(D_INNER.DEPTNO)
410+
FROM DEPT D_INNER
411+
WHERE D_INNER.DEPTNO = E.DEPTNO);
412+
+-------+
413+
| EMPNO |
414+
+-------+
415+
| 7369 |
416+
| 7499 |
417+
| 7521 |
418+
| 7566 |
419+
| 7654 |
420+
| 7698 |
421+
| 7782 |
422+
| 7788 |
423+
| 7839 |
424+
| 7844 |
425+
| 7876 |
426+
| 7900 |
427+
| 7902 |
428+
| 7934 |
429+
+-------+
430+
(14 rows)
431+
432+
!ok
433+
434+
SELECT e1.empno
435+
FROM emp e1,
436+
dept d1
437+
where e1.deptno = d1.deptno
438+
and e1.deptno < 10 and d1.deptno < 15
439+
and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno);
440+
+-------+
441+
| EMPNO |
442+
+-------+
443+
+-------+
444+
(0 rows)
445+
446+
!ok
447+
448+
SELECT e1.empno
449+
FROM emp e1, dept d1
450+
where e1.deptno = d1.deptno
451+
and e1.deptno < 10 and d1.deptno < 15
452+
and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)
453+
order by e1.empno;
454+
+-------+
455+
| EMPNO |
456+
+-------+
457+
+-------+
458+
(0 rows)
459+
460+
!ok
461+
404462
# End new-decorr.iq

0 commit comments

Comments
 (0)