Skip to content

Commit

Permalink
[BugFix] ScanNode of SkeletonNode compare operation adapt to external…
Browse files Browse the repository at this point in the history
… table (#53400)

Signed-off-by: stephen <[email protected]>
  • Loading branch information
stephen-shelby authored Dec 2, 2024
1 parent 1d478bd commit e88d410
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public ShowResultSet visitClearPlanAdvisorStatement(ClearPlanAdvisorStmt stmt, C
String result = String.format("Clear all plan advisor in FE(%s) successfully. Advisor size: %d",
GlobalStateMgr.getCurrentState().getNodeMgr().getNodeName(), size);
return new ShowResultSet(COLUMN_META, List.of(List.of(result)));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public void clearAllAdvisor() {
optimizedQueryRecords.clear();
}



public void deleteTuningGuides(UUID queryId) {
for (Map.Entry<PlanTuningCacheKey, OperatorTuningGuides> entry : cache.asMap().entrySet()) {
if (entry.getValue().getOriginalQueryId().equals(queryId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ public class ScanNode extends SkeletonNode {

private final long tableId;

private final String tableName;
private final String tableIdentifier;

public ScanNode(OptExpression optExpression,
NodeExecStats nodeExecStats, SkeletonNode parent) {
super(optExpression, nodeExecStats, parent);
PhysicalScanOperator scanOperator = (PhysicalScanOperator) optExpression.getOp();
tableId = scanOperator.getTable().getId();
tableName = scanOperator.getTable().getName();
tableIdentifier = scanOperator.getTable().getTableIdentifier();
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), tableId);
public long getTableId() {
return tableId;
}

public String getTableIdentifier() {
return tableIdentifier;
}

@Override
Expand All @@ -45,14 +48,18 @@ public boolean equals(Object o) {
return true;
}

if (!super.equals(o)) {
if (o == null || getClass() != o.getClass()) {
return false;
}

if (o == null || getClass() != o.getClass()) {
if (!super.equals(o)) {
return false;
}
ScanNode scanNode = (ScanNode) o;
return tableId == scanNode.tableId;
return tableId == scanNode.tableId && Objects.equals(tableIdentifier, scanNode.tableIdentifier);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), tableId, tableIdentifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.starrocks.qe.feedback.analyzer;

import com.google.common.base.Predicates;
import com.google.common.collect.Maps;
import com.starrocks.common.FeConstants;
import com.starrocks.common.Pair;
Expand All @@ -22,15 +23,19 @@
import com.starrocks.qe.feedback.guide.LeftChildEstimationErrorTuningGuide;
import com.starrocks.qe.feedback.guide.RightChildEstimationErrorTuningGuide;
import com.starrocks.qe.feedback.guide.StreamingAggTuningGuide;
import com.starrocks.qe.feedback.skeleton.ScanNode;
import com.starrocks.qe.feedback.skeleton.SkeletonBuilder;
import com.starrocks.qe.feedback.skeleton.SkeletonNode;
import com.starrocks.sql.optimizer.OptExpression;
import com.starrocks.sql.plan.DistributedEnvPlanTestBase;
import com.starrocks.sql.plan.ExecPlan;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -114,4 +119,24 @@ void testJoinAnalyzer() throws Exception {
Assert.assertTrue(tuningGuides.getTuningGuides(5).get(0) instanceof LeftChildEstimationErrorTuningGuide);
}
}

@Test
public void testSameScanNode() throws Exception {
String sql = "select * from customer l join customer r on l.c_custkey = r.c_custkey";
ExecPlan execPlan = getExecPlan(sql);
OptExpression root = execPlan.getPhysicalPlan();
NodeExecStats left = new NodeExecStats(0, 500, 500, 0, 0, 0);
NodeExecStats right = new NodeExecStats(1, 20000000, 20000000, 0, 0, 0);
Map<Integer, NodeExecStats> map = Maps.newHashMap();
map.put(0, left);
map.put(1, right);
SkeletonBuilder skeletonBuilder = new SkeletonBuilder(map);
Pair<SkeletonNode, Map<Integer, SkeletonNode>> pair = skeletonBuilder.buildSkeleton(root);
SkeletonNode rootSkeletonNode = pair.first;
List<ScanNode> scanNodeList = new ArrayList<>();
rootSkeletonNode.collectAll(Predicates.instanceOf(ScanNode.class), scanNodeList);
Assertions.assertNotEquals(scanNodeList.get(0), scanNodeList.get(1));
Assertions.assertEquals(scanNodeList.get(0).getTableIdentifier(), scanNodeList.get(1).getTableIdentifier());
Assertions.assertEquals(scanNodeList.get(0).getTableId(), scanNodeList.get(1).getTableId());
}
}

0 comments on commit e88d410

Please sign in to comment.