[fix](statistics)Reanalyze olapTable if getRowCount is not 0 and last time row count is 0 (#30096)
Sample analyze may write 0 result if getRowCount is not updated while analyzing. So we need to reanalyze the table if getRowCount > 0 and previous analyze row count is 0. Otherwise the stats for this table may stay 0 for ever before user load new data to this table.
This commit is contained in:
@ -1193,6 +1193,9 @@ public class OlapTable extends Table {
|
||||
return true;
|
||||
}
|
||||
long rowCount = getRowCount();
|
||||
if (rowCount > 0 && tblStats.rowCount == 0) {
|
||||
return true;
|
||||
}
|
||||
long updateRows = tblStats.updatedRows.get();
|
||||
int tblHealth = StatisticsUtil.getTableHealth(rowCount, updateRows);
|
||||
return tblHealth < StatisticsUtil.getTableStatsHealthThreshold();
|
||||
|
||||
@ -545,7 +545,7 @@ public class AnalysisManager implements Writable {
|
||||
}
|
||||
TableStatsMeta tableStats = findTableStatsStatus(tbl.getId());
|
||||
if (tableStats == null) {
|
||||
updateTableStatsStatus(new TableStatsMeta(tbl.estimatedRowCount(), jobInfo, tbl));
|
||||
updateTableStatsStatus(new TableStatsMeta(jobInfo.emptyJob ? 0 : tbl.estimatedRowCount(), jobInfo, tbl));
|
||||
} else {
|
||||
tableStats.update(jobInfo, tbl);
|
||||
logCreateTableStats(tableStats);
|
||||
|
||||
@ -209,7 +209,7 @@ public class StatisticsAutoCollector extends StatisticsCollector {
|
||||
@VisibleForTesting
|
||||
protected AnalysisInfo getReAnalyzeRequiredPart(AnalysisInfo jobInfo) {
|
||||
TableIf table = StatisticsUtil.findTable(jobInfo.catalogId, jobInfo.dbId, jobInfo.tblId);
|
||||
// Skip tables that are too width.
|
||||
// Skip tables that are too wide.
|
||||
if (table.getBaseSchema().size() > StatisticsUtil.getAutoAnalyzeTableWidthThreshold()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ public class TableStatsMeta implements Writable {
|
||||
jobType = analyzedJob.jobType;
|
||||
if (tableIf != null) {
|
||||
if (tableIf instanceof OlapTable) {
|
||||
rowCount = tableIf.getRowCount();
|
||||
rowCount = analyzedJob.emptyJob ? 0 : tableIf.getRowCount();
|
||||
}
|
||||
if (!analyzedJob.emptyJob && analyzedJob.colToPartitions.keySet()
|
||||
.containsAll(tableIf.getBaseSchema().stream()
|
||||
|
||||
Reference in New Issue
Block a user