From e88d410e1967614e32e1f8061ddce9aff7164e80 Mon Sep 17 00:00:00 2001 From: stephen <91597003+stephen-shelby@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:08:29 +0800 Subject: [PATCH] [BugFix] ScanNode of SkeletonNode compare operation adapt to external table (#53400) Signed-off-by: stephen --- .../qe/feedback/PlanAdvisorExecutor.java | 1 - .../qe/feedback/PlanTuningAdvisor.java | 2 -- .../qe/feedback/skeleton/ScanNode.java | 25 ++++++++++++------- .../analyzer/PlanTuningAnalyzerTest.java | 25 +++++++++++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanAdvisorExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanAdvisorExecutor.java index 089d47c037cf4..6c2ae70529c7d 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanAdvisorExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanAdvisorExecutor.java @@ -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 diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanTuningAdvisor.java b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanTuningAdvisor.java index 9fc9cef95e189..01bb223787b4b 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanTuningAdvisor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/PlanTuningAdvisor.java @@ -76,8 +76,6 @@ public void clearAllAdvisor() { optimizedQueryRecords.clear(); } - - public void deleteTuningGuides(UUID queryId) { for (Map.Entry entry : cache.asMap().entrySet()) { if (entry.getValue().getOriginalQueryId().equals(queryId)) { diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/skeleton/ScanNode.java b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/skeleton/ScanNode.java index 7fe844358ba49..0ff0d3575998a 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/feedback/skeleton/ScanNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/feedback/skeleton/ScanNode.java @@ -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 @@ -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); } } diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/feedback/analyzer/PlanTuningAnalyzerTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/feedback/analyzer/PlanTuningAnalyzerTest.java index d2b48bdb9e3be..fabb2ee18524a 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/feedback/analyzer/PlanTuningAnalyzerTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/feedback/analyzer/PlanTuningAnalyzerTest.java @@ -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; @@ -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; @@ -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 map = Maps.newHashMap(); + map.put(0, left); + map.put(1, right); + SkeletonBuilder skeletonBuilder = new SkeletonBuilder(map); + Pair> pair = skeletonBuilder.buildSkeleton(root); + SkeletonNode rootSkeletonNode = pair.first; + List 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()); + } } \ No newline at end of file