Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,23 @@ private boolean canColocateJoin(HashJoinNode node, PlanNode leftRoot, PlanNode r
OlapTable leftTable = ((OlapScanNode) leftRoot).getOlapTable();
OlapTable rightTable = ((OlapScanNode) rightRoot).getOlapTable();

ColocateTableIndex colocateIndex = Catalog.getCurrentColocateIndex();

//1 the table must be colocate
if (!colocateIndex.isSameGroup(leftTable.getId(), rightTable.getId())) {
cannotReason.add("table not in same group");
return false;
}
// if left table and right table is same table, they are naturally colocate relationship
// no need to check colocate group
if (leftTable.getId() != rightTable.getId()) {
ColocateTableIndex colocateIndex = Catalog.getCurrentColocateIndex();

//1 the table must be colocate
if (!colocateIndex.isSameGroup(leftTable.getId(), rightTable.getId())) {
cannotReason.add("table not in the same group");
return false;
}

//2 the colocate group must be stable
GroupId groupId = colocateIndex.getGroup(leftTable.getId());
if (colocateIndex.isGroupUnstable(groupId)) {
cannotReason.add("group is not stable");
return false;
//2 the colocate group must be stable
GroupId groupId = colocateIndex.getGroup(leftTable.getId());
if (colocateIndex.isGroupUnstable(groupId)) {
cannotReason.add("group is not stable");
return false;
}
}

DistributionInfo leftDistribution = leftTable.getDefaultDistributionInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,13 @@ public void testColocateJoin() throws Exception {
Assert.assertTrue(explainString.contains("colocate: false"));
}

@Test
public void testSelfColocateJoin() throws Exception {
String queryStr = "explain select * from test.jointest t1, test.jointest t2 where t1.k1 = t2.k1";
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
Assert.assertTrue(explainString.contains("colocate: true"));
}

@Test
public void testJoinWithMysqlTable() throws Exception {
connectContext.setDatabase("default_cluster:test");
Expand Down