This is an automated email from the ASF dual-hosted git repository.

silun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 66c496a6a0 [CALCITE-7434] Error in new decorrelation algorithm caused 
by FilterJoinRule omitting variablesSet
66c496a6a0 is described below

commit 66c496a6a0187f38dcd87e2e20f4449505db8740
Author: Silun Dong <[email protected]>
AuthorDate: Fri Mar 6 16:29:12 2026 +0800

    [CALCITE-7434] Error in new decorrelation algorithm caused by 
FilterJoinRule omitting variablesSet
---
 .../apache/calcite/rel/rules/FilterJoinRule.java   |  2 +
 .../org/apache/calcite/test/RelOptRulesTest.xml    |  2 +-
 core/src/test/resources/sql/new-decorr.iq          | 58 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
index 9c6b560bfa..d4e1473ccb 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
@@ -36,6 +36,7 @@
 import org.apache.calcite.tools.RelBuilderFactory;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -249,6 +250,7 @@ protected void perform(RelOptRuleCall call, @Nullable 
Filter filter,
 
     // create a FilterRel on top of the join if needed
     relBuilder.filter(
+        filter == null ? ImmutableSet.of() : filter.getVariablesSet(),
         RexUtil.fixUp(rexBuilder, aboveFilters,
             RelOptUtil.getFieldTypeList(relBuilder.peek().getRowType())));
     call.transformTo(relBuilder.build());
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index e2f83bf2c1..a16c920095 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -5685,7 +5685,7 @@ LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
   LogicalProject(DEPTNO=[$0])
     LogicalFilter(condition=[=($0, $cor0.DEPTNO)])
       LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
-}))])
+}))], variablesSet=[[$cor0]])
     LogicalJoin(condition=[=($7, $9)], joinType=[inner])
       LogicalFilter(condition=[>($0, 10)])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
diff --git a/core/src/test/resources/sql/new-decorr.iq 
b/core/src/test/resources/sql/new-decorr.iq
index 73ed32f386..e7fe98e178 100644
--- a/core/src/test/resources/sql/new-decorr.iq
+++ b/core/src/test/resources/sql/new-decorr.iq
@@ -401,4 +401,62 @@ EnumerableCalc(expr#0..3=[{inputs}], ENAME=[$t1], 
JOB=[$t2], SAL=[$t3])
 !plan
 !}
 
+# [CALCITE-7434] Error in new decorrelation algorithm caused by FilterJoinRule 
omitting variablesSet
+SELECT E.EMPNO
+FROM EMP E
+JOIN DEPT D ON E.DEPTNO = D.DEPTNO
+WHERE E.EMPNO > 10 AND D.DEPTNO = (
+    SELECT MIN(D_INNER.DEPTNO)
+    FROM DEPT D_INNER
+    WHERE D_INNER.DEPTNO = E.DEPTNO);
++-------+
+| EMPNO |
++-------+
+|  7369 |
+|  7499 |
+|  7521 |
+|  7566 |
+|  7654 |
+|  7698 |
+|  7782 |
+|  7788 |
+|  7839 |
+|  7844 |
+|  7876 |
+|  7900 |
+|  7902 |
+|  7934 |
++-------+
+(14 rows)
+
+!ok
+
+SELECT e1.empno
+FROM emp e1,
+  dept d1
+where e1.deptno = d1.deptno
+and e1.deptno < 10 and d1.deptno < 15
+and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno);
++-------+
+| EMPNO |
++-------+
++-------+
+(0 rows)
+
+!ok
+
+SELECT e1.empno
+FROM emp e1, dept d1
+where e1.deptno = d1.deptno
+and e1.deptno < 10 and d1.deptno < 15
+and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)
+order by e1.empno;
++-------+
+| EMPNO |
++-------+
++-------+
+(0 rows)
+
+!ok
+
 # End new-decorr.iq

Reply via email to