starocean999 commented on code in PR #48031:
URL: https://github.com/apache/doris/pull/48031#discussion_r1960880111


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java:
##########
@@ -186,6 +190,120 @@ public void createAnalyze(AnalyzeStmt analyzeStmt, 
boolean proxy) throws DdlExce
         }
     }
 
+    // for nereids analyze database/table
+    public void createAnalyze(AnalyzeCommand command, boolean proxy) throws 
DdlException, AnalysisException {
+        if (!StatisticsUtil.statsTblAvailable() && 
!FeConstants.runningUnitTest) {
+            throw new DdlException("Stats table not available, please make 
sure your cluster status is normal");
+        }
+        if (ConnectContext.get().getSessionVariable().forceSampleAnalyze) {
+            command.checkAndSetSample();
+        }
+        if (command.getAnalyzeOp() instanceof AnalyzeDatabaseOp) {
+            createAnalysisJobs((AnalyzeDatabaseOp) command.getAnalyzeOp(), 
proxy);
+        } else if (command.getAnalyzeOp() instanceof AnalyzeTableOp) {
+            createAnalysisJob((AnalyzeTableOp) command.getAnalyzeOp(), proxy);
+        }
+    }
+
+    // for nereids analyze database/table
+    public void createAnalysisJobs(AnalyzeDatabaseOp op, boolean proxy) throws 
AnalysisException {
+        DatabaseIf<TableIf> db = op.getDb();
+        List<AnalysisInfo> analysisInfos = buildAnalysisInfosForDBV2(db, 
op.getAnalyzeProperties());
+        if (!op.isSync()) {
+            sendJobId(analysisInfos, proxy);
+        }
+    }
+
+    // for nereids analyze database/table
+    public void createAnalysisJob(AnalyzeTableOp op, boolean proxy) throws 
DdlException {
+        // Using auto analyzer if user specifies.
+        if 
("true".equalsIgnoreCase(op.getAnalyzeProperties().getProperties().get("use.auto.analyzer")))
 {
+            
Env.getCurrentEnv().getStatisticsAutoCollector().processOneJob(op.getTable(),
+                    op.getTable().getColumnIndexPairs(op.getColumnNames()), 
JobPriority.HIGH);
+            return;
+        }
+        AnalysisInfo jobInfo = buildAndAssignJob(op);
+        if (jobInfo == null) {
+            return;
+        }
+        sendJobId(ImmutableList.of(jobInfo), proxy);
+    }
+
+    // for nereids analyze database/table
+    @Nullable
+    @VisibleForTesting
+    protected AnalysisInfo buildAndAssignJob(AnalyzeTableOp op) throws 
DdlException {
+        AnalysisInfo jobInfo = buildAnalysisJobInfo(op);
+        if (jobInfo.jobColumns == null || jobInfo.jobColumns.isEmpty()) {
+            // No statistics need to be collected or updated
+            LOG.info("Job columns are empty, skip analyze table {}", 
op.getTblName().toString());
+            return null;
+        }
+        // Only OlapTable and Hive HMSExternalTable support sample analyze.
+        if ((op.getSamplePercent() > 0 || op.getSampleRows() > 0) && 
!canSample(op.getTable())) {
+            String message = String.format("Table %s doesn't support sample 
analyze.", op.getTable().getName());
+            LOG.info(message);
+            throw new DdlException(message);
+        }
+
+        boolean isSync = op.isSync();
+        Map<Long, BaseAnalysisTask> analysisTaskInfos = new HashMap<>();
+        createTaskForEachColumns(jobInfo, analysisTaskInfos, isSync);
+        constructJob(jobInfo, analysisTaskInfos.values());
+        if (isSync) {
+            syncExecute(analysisTaskInfos.values());
+            jobInfo.state = AnalysisState.FINISHED;
+            updateTableStats(jobInfo);
+            return null;
+        }
+        recordAnalysisJob(jobInfo);
+        analysisJobIdToTaskMap.put(jobInfo.jobId, analysisTaskInfos);
+        if (!jobInfo.scheduleType.equals(ScheduleType.PERIOD)) {
+            analysisTaskInfos.values().forEach(taskExecutor::submitTask);
+        }
+        return jobInfo;
+    }
+
+    // for nereids analyze database/table
+    public List<AnalysisInfo> buildAnalysisInfosForDBV2(DatabaseIf<TableIf> 
db, AnalyzeProperties analyzeProperties)

Review Comment:
   ```suggestion
       public List<AnalysisInfo> 
buildAnalysisInfosForNereidsDB(DatabaseIf<TableIf> db, AnalyzeProperties 
analyzeProperties)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to