Skip to content

Commit

Permalink
[BugFix] Fix join reorder init error (#51766)
Browse files Browse the repository at this point in the history
Signed-off-by: Seaven <[email protected]>
(cherry picked from commit 5697e64)
  • Loading branch information
Seaven authored and mergify[bot] committed Oct 12, 2024
1 parent 1164fc7 commit 955e6fc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,20 @@ private static void flattenJoinNode(OptExpression node, LinkedHashSet<OptExpress

if (joinOperator.getProjection() != null) {
Projection projection = joinOperator.getProjection();

for (Map.Entry<ColumnRefOperator, ScalarOperator> entry : projection.getColumnRefMap().entrySet()) {
if (!entry.getValue().isColumnRef()
&& entry.getValue().getUsedColumns().isIntersect(node.inputAt(0).getOutputColumns())
&& entry.getValue().getUsedColumns().isIntersect(node.inputAt(1).getOutputColumns())) {
atoms.add(node);
return;
}

if (!entry.getKey().equals(entry.getValue())) {
expressionMap.put(entry.getKey(), entry.getValue());
}
boolean fromTwoChildren = projection.getColumnRefMap().values().stream().anyMatch(v -> {
ColumnRefSet useRefs = v.getUsedColumns();
return !v.isColumnRef() && useRefs.isIntersect(node.inputAt(0).getOutputColumns())
&& useRefs.isIntersect(node.inputAt(1).getOutputColumns());
});
if (fromTwoChildren) {
atoms.add(node);
return;
}
projection.getColumnRefMap().forEach((k, v) -> {
if (!k.equals(v)) {
expressionMap.put(k, v);
}
});
}

flattenJoinNode(node.inputAt(0), atoms, predicates, expressionMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,4 +890,11 @@ public void testPruneTableNPE() throws Exception {
connectContext.getSessionVariable().replayFromJson(savedSv);
}
}

@Test
public void testJoinInitError() throws Exception {
Pair<QueryDumpInfo, String> replayPair =
getCostPlanFragment(getDumpInfoFromFile("query_dump/join_init_error"));
Assert.assertTrue(replayPair.second, replayPair.second.contains("HASH JOIN"));
}
}
Loading

0 comments on commit 955e6fc

Please sign in to comment.