github-actions[bot] commented on code in PR #70994:
URL: https://github.com/apache/doris/pull/70994#discussion_r4690563099


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/analysis/ColumnMinMaxBatchCollector.java:
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.statistics.analysis;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.MaterializedIndexMeta;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.common.Status;
+import org.apache.doris.qe.AutoCloseConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.statistics.repository.ResultRow;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CancellationException;
+import java.util.stream.Collectors;
+
+/** Shares bounds only between columns selected for table sampling at job 
creation. */
+final class ColumnMinMaxBatchCollector {
+    private static final Logger LOG = 
LogManager.getLogger(ColumnMinMaxBatchCollector.class);
+
+    private enum State {
+        PENDING, RUNNING, SUCCEEDED, FALLBACK, CANCELLED
+    }
+
+    private record Target(long jobId, long indexId, String qualifiedTable, 
String indexSql, boolean aggregated) {
+    }
+
+    private final List<Batch> batches = new ArrayList<>();
+    // Guarded by this collector's monitor. Never execute or cancel SQL under 
the monitor.
+    private boolean heavyBatchRunning;
+
+    ColumnMinMaxBatchCollector(Collection<? extends BaseAnalysisTask> tasks, 
int batchSize) {
+        if (batchSize <= 1) {
+            return;
+        }
+        Map<Target, Map<String, List<OlapAnalysisTask>>> groups = new 
HashMap<>();
+        for (BaseAnalysisTask task : tasks) {
+            if (!(task instanceof OlapAnalysisTask olapTask) || 
task.tableSample == null || task.info.rowCount == 0) {
+                continue;
+            }
+            OlapTable table = (OlapTable) task.tbl;
+            long indexId = task.info.indexId;
+            MaterializedIndexMeta meta = table.getIndexMetaByIndexId(indexId 
== -1 ? table.getBaseIndexId() : indexId);
+            Column column = meta == null ? null : 
meta.getColumnByName(task.info.colName);
+            // DDL can remove a column, and getColumnByName also strips 
embedded backticks.
+            // Only batch a physical column that matches the SQL identifier 
the task would query.
+            if (column != null && 
column.getName().equalsIgnoreCase(task.info.colName)) {
+                Target target = new Target(task.info.jobId, indexId, 
olapTask.qualifiedTableName(),

Review Comment:
   [P2] Resolve table names when the batch actually executes
   
   The qualified table/index names are cached before tasks enter the executor 
queue, but an ANALYZE job does not hold a table lock or get cancelled by 
`Env.renameTable`. If a sampled job for `t` is queued, then `t` is renamed to 
`t_old` and a replacement `t` with the same columns is created before the 
worker starts, this batch successfully reads the replacement's bounds. 
`doSample()` subsequently builds SQL from the original table object's current 
name (`t_old`) and retains its original table ID, so it persists the 
replacement's min/max as statistics of `t_old`. For a nonempty table smaller 
than SAMPLE ROWS, the later query has no tablet hint and succeeds, so fallback 
cannot catch this. Previously both queries resolved the current name at 
execution. Keep stable IDs for grouping and resolve/validate the current table 
and index names before executing the batch.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to