From bd2280b4ce702e24cc31ca1d379aeaf6f00ce69c Mon Sep 17 00:00:00 2001 From: AKIRA <33112463+Kikyou1997@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:42:12 +0800 Subject: [PATCH] [fix](planner) move join reorder to the single node planner (#15817) Reorder in analyze phase would produce a stmt which its corresponding SQL could not be analyzed correctly and cause an analyze exception that may be happened in the stmt rewrite, since the rewriter will reset and reanalyze the rewritten stmt. --- .../java/org/apache/doris/analysis/SelectStmt.java | 6 +----- .../apache/doris/planner/SingleNodePlanner.java | 5 +++++ .../doris/statistics/AnalysisTaskExecutorTest.java | 14 ++++---------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index d29f366557..f4915a4e58 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -598,10 +598,6 @@ public class SelectStmt extends QueryStmt { if (needToSql) { sqlString = toSql(); } - if (analyzer.enableStarJoinReorder()) { - LOG.debug("use old reorder logical in select stmt"); - reorderTable(analyzer); - } resolveInlineViewRefs(analyzer); @@ -793,7 +789,7 @@ public class SelectStmt extends QueryStmt { } } - protected void reorderTable(Analyzer analyzer) throws AnalysisException { + public void reorderTable(Analyzer analyzer) throws AnalysisException { List> candidates = Lists.newArrayList(); ArrayList originOrderBackUp = Lists.newArrayList(fromClause.getTableRefs()); // New pair of table ref and row count diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index 718cafd980..129c1691cf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -1116,6 +1116,11 @@ public class SingleNodePlanner { return createConstantSelectPlan(selectStmt, analyzer); } + if (analyzer.enableStarJoinReorder()) { + LOG.debug("use old reorder logical in select stmt"); + selectStmt.reorderTable(analyzer); + } + // Slot materialization: // We need to mark all slots as materialized that are needed during the execution // of selectStmt, and we need to do that prior to creating plans for the TableRefs diff --git a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisTaskExecutorTest.java b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisTaskExecutorTest.java index 6d7b3b4e43..ba75d26cec 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisTaskExecutorTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisTaskExecutorTest.java @@ -67,23 +67,17 @@ public class AnalysisTaskExecutorTest extends TestWithFeService { .build(); OlapAnalysisTask analysisJob = new OlapAnalysisTask(analysisTaskScheduler, analysisJobInfo); - new Expectations() { - { - analysisTaskScheduler.getPendingTasks(); - result = analysisJob; + new MockUp() { + public synchronized BaseAnalysisTask getPendingTasks() { + return analysisJob; } }; + AnalysisTaskExecutor analysisTaskExecutor = new AnalysisTaskExecutor(analysisTaskScheduler); BlockingQueue b = Deencapsulation.getField(analysisTaskExecutor, "jobQueue"); AnalysisTaskWrapper analysisTaskWrapper = new AnalysisTaskWrapper(analysisTaskExecutor, analysisJob); Deencapsulation.setField(analysisTaskWrapper, "startTime", 5); b.put(analysisTaskWrapper); - new Expectations() { - { - analysisTaskWrapper.cancel(); - times = 1; - } - }; analysisTaskExecutor.start(); BlockingCounter counter = Deencapsulation.getField(analysisTaskExecutor, "blockingCounter"); int sleepTime = 500;