Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ public void createAnalysisJob(AnalyzeTblStmt stmt, boolean proxy) throws DdlExce
@VisibleForTesting
protected AnalysisInfo buildAndAssignJob(AnalyzeTblStmt stmt) throws DdlException {
AnalysisInfo jobInfo = buildAnalysisJobInfo(stmt);
if (jobInfo.jobColumns.isEmpty()) {
if (jobInfo.jobColumns == null || jobInfo.jobColumns.isEmpty()) {
// No statistics need to be collected or updated
LOG.info("Job columns are empty, skip analyze table {}", stmt.getTblName().toString());
return null;
}
// Only OlapTable and Hive HMSExternalTable support sample analyze.
Expand Down Expand Up @@ -371,8 +372,7 @@ public AnalysisInfo buildAnalysisJobInfo(AnalyzeTblStmt stmt) {
infoBuilder.setColName(stringJoiner.toString());
infoBuilder.setTaskIds(Lists.newArrayList());
infoBuilder.setTblUpdateTime(table.getUpdateTime());
long rowCount = table.getRowCount();
infoBuilder.setRowCount(rowCount);
infoBuilder.setRowCount(StatisticsUtil.isEmptyTable(table, analysisMethod) ? 0 : table.getRowCount());
TableStatsMeta tableStatsStatus = findTableStatsStatus(table.getId());
infoBuilder.setUpdateRows(tableStatsStatus == null ? 0 : tableStatsStatus.updatedRows.get());
infoBuilder.setPriority(JobPriority.MANUAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ protected boolean needLimit(long sizeToRead, double factor) {
}
target = columnSize * tableSample.getSampleValue();
}
if (sizeToRead > LIMIT_SIZE && sizeToRead > target * LIMIT_FACTOR) {
return true;
}
return false;
return sizeToRead > LIMIT_SIZE && sizeToRead > target * LIMIT_FACTOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -65,11 +64,11 @@ public OlapAnalysisTask(AnalysisInfo info) {
}

public void doExecute() throws Exception {
Set<Pair<String, String>> columnList = info.jobColumns;
if (StatisticsUtil.isEmptyTable(tbl, info.analysisMethod) || columnList == null || columnList.isEmpty()) {
// For empty table, write empty result directly, no need to run SQL to collect stats.
if (info.rowCount == 0) {
StatsId statsId = new StatsId(concatColumnStatsId(), info.catalogId, info.dbId,
info.tblId, info.indexId, info.colName, null);
job.appendBuf(this, Arrays.asList(new ColStatsData(statsId)));
job.appendBuf(this, Collections.singletonList(new ColStatsData(statsId)));
return;
}
if (tableSample != null) {
Expand All @@ -84,7 +83,7 @@ public void doExecute() throws Exception {
* 2. estimate partition stats
* 3. insert col stats and partition stats
*/
protected void doSample() throws Exception {
protected void doSample() {
if (LOG.isDebugEnabled()) {
LOG.debug("Will do sample collection for column {}", col.getName());
}
Expand Down Expand Up @@ -209,7 +208,7 @@ protected ResultRow collectBasicStat(AutoCloseConnectContext context) {
* 2. insert partition in batch
* 3. calculate column stats based on partition stats
*/
protected void doFull() throws Exception {
protected void doFull() {
if (LOG.isDebugEnabled()) {
LOG.debug("Will do full collection for column {}", col.getName());
}
Expand Down Expand Up @@ -315,10 +314,7 @@ protected boolean needLimit() {
return false;
}
// Partition column need to scan tablets from all partitions.
if (tbl.isPartitionColumn(col.getName())) {
return false;
}
return true;
return !tbl.isPartitionColumn(col.getName());
}

/**
Expand Down Expand Up @@ -381,12 +377,6 @@ protected boolean isSingleUniqueKey() {
}

protected String concatColumnStatsId() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(info.tblId);
stringBuilder.append("-");
stringBuilder.append(info.indexId);
stringBuilder.append("-");
stringBuilder.append(info.colName);
return stringBuilder.toString();
return info.tblId + "-" + info.indexId + "-" + info.colName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected Pair<Entry<TableName, Set<Pair<String, String>>>, JobPriority> getJob(
return Pair.of(job.get(), JobPriority.MID);
}
job = fetchJobFromMap(manager.lowPriorityJobs);
return job.map(tableNameSetEntry -> Pair.of(tableNameSetEntry, JobPriority.LOW)).orElse(null);
return job.map(entry -> Pair.of(entry, JobPriority.LOW)).orElse(null);
}

protected Optional<Map.Entry<TableName, Set<Pair<String, String>>>> fetchJobFromMap(
Expand Down Expand Up @@ -183,7 +183,7 @@ protected AnalysisInfo createAnalyzeJobForTbl(
? AnalysisMethod.SAMPLE : AnalysisMethod.FULL;
AnalysisManager manager = Env.getServingEnv().getAnalysisManager();
TableStatsMeta tableStatsStatus = manager.findTableStatsStatus(table.getId());
long rowCount = table.getRowCount();
long rowCount = StatisticsUtil.isEmptyTable(table, analysisMethod) ? 0 : table.getRowCount();
StringJoiner stringJoiner = new StringJoiner(",", "[", "]");
for (Pair<String, String> pair : jobColumns) {
stringJoiner.add(pair.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ public static boolean isMvColumn(TableIf table, String columnName) {
}

public static boolean isEmptyTable(TableIf table, AnalysisInfo.AnalysisMethod method) {
int waitRowCountReportedTime = 90;
int waitRowCountReportedTime = 75;
if (!(table instanceof OlapTable) || method.equals(AnalysisInfo.AnalysisMethod.FULL)) {
return false;
}
Expand Down