Skip to content

Commit

Permalink
[CALCITE-3643] Prevent matching JoinCommuteRule when both inputs are …
Browse files Browse the repository at this point in the history
…the same

=($0, $1) and =($1, $1) are equivalent, however adding that permutation
increases search space.
  • Loading branch information
vlsi committed Dec 29, 2019
1 parent 0341e97 commit 8768a23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.function.Predicate;

/**
* Planner rule that permutes the inputs to a
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -143,11 +150,6 @@ public static RelNode swap(Join join, boolean swapOuterJoins,
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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/sql/join.iq
Original file line number Diff line number Diff line change
Expand Up @@ -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=[$t1], $f16=[$t5])
EnumerableHashJoin(condition=[=($1, $3)], joinType=[inner])
EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], DEPTNO=[$t7])
EnumerableTableScan(table=[[scott, EMP]])
Expand Down

0 comments on commit 8768a23

Please sign in to comment.