This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 803ab515589 [opt](statistics) Add wait row count reported logic for
sample analyze. (#32030)
803ab515589 is described below
commit 803ab5155897cdcc423300dacfcb75b6659d6bab
Author: Jibing-Li <[email protected]>
AuthorDate: Wed Mar 13 10:51:39 2024 +0800
[opt](statistics) Add wait row count reported logic for sample analyze.
(#32030)
If getRowCount returns 0, and table visible version is 2, the table is
probably not empty, so we wait a moment for the row count to be reported.
---
.../apache/doris/statistics/OlapAnalysisTask.java | 2 +-
.../doris/statistics/util/StatisticsUtil.java | 26 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/OlapAnalysisTask.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/OlapAnalysisTask.java
index 5a1d5829c8c..5e04c315713 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/OlapAnalysisTask.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/OlapAnalysisTask.java
@@ -65,7 +65,7 @@ public class OlapAnalysisTask extends BaseAnalysisTask {
public void doExecute() throws Exception {
Set<String> partitionNames = info.colToPartitions.get(info.colName);
- if ((info.emptyJob &&
info.analysisMethod.equals(AnalysisInfo.AnalysisMethod.SAMPLE))
+ if (StatisticsUtil.isEmptyTable(tbl, info.analysisMethod)
|| partitionNames == null || partitionNames.isEmpty()) {
if (partitionNames == null) {
LOG.warn("Table {}.{}.{}, partitionNames for column {} is
null. ColToPartitions:[{}]",
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
index 3df7385d970..875b102fb04 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
@@ -45,6 +45,7 @@ import org.apache.doris.catalog.PartitionItem;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.StructType;
+import org.apache.doris.catalog.TableAttributes;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.VariantType;
@@ -68,6 +69,7 @@ import org.apache.doris.qe.QueryState;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.qe.VariableMgr;
+import org.apache.doris.statistics.AnalysisInfo;
import org.apache.doris.statistics.ColumnStatistic;
import org.apache.doris.statistics.ColumnStatisticBuilder;
import org.apache.doris.statistics.Histogram;
@@ -991,4 +993,28 @@ public class StatisticsUtil {
||
columnName.startsWith(CreateMaterializedViewStmt.MATERIALIZED_VIEW_AGGREGATE_NAME_PREFIX);
}
+ public static boolean isEmptyTable(TableIf table,
AnalysisInfo.AnalysisMethod method) {
+ int waitRowCountReportedTime = 90;
+ if (!(table instanceof OlapTable) ||
method.equals(AnalysisInfo.AnalysisMethod.FULL)) {
+ return false;
+ }
+ OlapTable olapTable = (OlapTable) table;
+ for (int i = 0; i < waitRowCountReportedTime; i++) {
+ if (olapTable.getRowCount() > 0) {
+ return false;
+ }
+ // If visible version is 2, table is probably not empty. So we
wait row count to be reported.
+ // If visible version is not 2 and getRowCount return 0, we assume
it is an empty table.
+ if (olapTable.getVisibleVersion() !=
TableAttributes.TABLE_INIT_VERSION + 1) {
+ return true;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.info("Sleep interrupted.", e);
+ }
+ }
+ return true;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]