You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vl...@apache.org on 2019/12/29 11:38:42 UTC
[calcite] 01/01: [CALCITE-3643] Prevent matching JoinCommuteRule
when both inputs are the same
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 49cb002479abdf0a3d95bcebc1ca424d52adbf40
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Sun Dec 29 13:32:50 2019 +0300
[CALCITE-3643] Prevent matching JoinCommuteRule when both inputs are the same
=($0, $1) and =($1, $1) are equivalent, however adding that permutation
increases search space.
---
.../java/org/apache/calcite/rel/rules/JoinCommuteRule.java | 14 ++++++++------
core/src/test/resources/sql/join.iq | 2 +-
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
index fe6f347..560a3fb 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
@@ -38,6 +38,7 @@ import org.apache.calcite.tools.RelBuilderFactory;
import com.google.common.collect.ImmutableList;
import java.util.List;
+import java.util.function.Predicate;
/**
* Planner rule that permutes the inputs to a
@@ -67,7 +68,13 @@ public class JoinCommuteRule extends RelOptRule {
*/
public JoinCommuteRule(Class<? extends Join> clazz,
RelBuilderFactory relBuilderFactory, boolean swapOuter) {
- super(operand(clazz, any()), relBuilderFactory, null);
+ // FIXME Enable this rule for joins with system fields
+ super(
+ operandJ(clazz, null,
+ (Predicate<Join>) j -> j.getLeft().getId() != j.getRight().getId()
+ && j.getSystemFieldList().isEmpty(),
+ any()),
+ relBuilderFactory, null);
this.swapOuter = swapOuter;
}
@@ -143,11 +150,6 @@ public class JoinCommuteRule extends RelOptRule {
public void onMatch(final RelOptRuleCall call) {
Join join = call.rel(0);
- if (!join.getSystemFieldList().isEmpty()) {
- // FIXME Enable this rule for joins with system fields
- return;
- }
-
final RelNode swapped = swap(join, this.swapOuter, call.builder());
if (swapped == null) {
return;
diff --git a/core/src/test/resources/sql/join.iq b/core/src/test/resources/sql/join.iq
index e771332..a798890 100644
--- a/core/src/test/resources/sql/join.iq
+++ b/core/src/test/resources/sql/join.iq
@@ -198,7 +198,7 @@ EnumerableCalc(expr#0..1=[{inputs}], DEPTNO=[$t1], ENAME=[$t0])
EnumerableHashJoin(condition=[=($2, $4)], joinType=[inner])
EnumerableCalc(expr#0..7=[{inputs}], expr#8=[10], expr#9=[+($t7, $t8)], proj#0..1=[{exprs}], $f8=[$t9])
EnumerableTableScan(table=[[scott, EMP]])
- EnumerableCalc(expr#0..3=[{inputs}], expr#4=[+($t3, $t1)], expr#5=[CAST($t4):INTEGER], DEPTNO=[$t3], $f16=[$t5])
+ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[+($t1, $t3)], expr#5=[CAST($t4):INTEGER], DEPTNO=[$t3], $f16=[$t5])
EnumerableHashJoin(condition=[=($1, $3)], joinType=[inner])
EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], DEPTNO=[$t7])
EnumerableTableScan(table=[[scott, EMP]])