Skip to content

Commit

Permalink
[CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
  • Loading branch information
mihaibudiu committed Apr 18, 2024
1 parent b4bcd3b commit 0551b89
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public MultiJoinOptimizeBushyRule(RelFactories.JoinFactory joinFactory,
final RelMetadataQuery mq = call.getMetadataQuery();

final LoptMultiJoin multiJoin = new LoptMultiJoin(multiJoinRel);
for (int i = 0; i < multiJoin.getNumJoinFactors(); i++) {
ImmutableBitSet outerJoinFactors = multiJoin.getOuterJoinFactors(i);
if (outerJoinFactors == null) {
continue;
}
if (!outerJoinFactors.isEmpty()) {
// Refuse to apply this rule to a multijoin with outer joins,
// since this rule cannot handle outer joins.
return;
}
}

final List<Vertex> vertexes = new ArrayList<>();
int x = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,15 @@ private void checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
.check();
}

/** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-5289">
* [CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule</a>. */
@Test void testBushyJoinRule() {
final String sql = "select emp.ename from emp LEFT JOIN emp AS emp1 on emp.ename = emp1.ename";
sql(sql).withPreRule(CoreRules.JOIN_TO_MULTI_JOIN)
.withRule(CoreRules.MULTI_JOIN_OPTIMIZE_BUSHY)
.checkUnchanged();
}

@Test void testConvertMultiJoinRule() {
final String sql = "select e1.ename from emp e1, dept d, emp e2\n"
+ "where e1.deptno = d.deptno and d.deptno = e2.deptno";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,19 @@ LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[BIT_O
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testBushyJoinRule">
<Resource name="sql">
<![CDATA[select emp.ename from emp LEFT JOIN emp AS emp1 on emp.ename = emp1.ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, =($1, $10)]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
Expand Down

0 comments on commit 0551b89

Please sign in to comment.