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 @@ -61,6 +61,8 @@ public class ShowColumnStatsStmt extends ShowStmt {
.add("trigger")
.add("query_times")
.add("updated_time")
.add("update_rows")
.add("last_analyze_row_count")
.build();

private final TableName tableName;
Expand Down Expand Up @@ -160,6 +162,8 @@ public ShowResultSet constructResultSet(List<Pair<Pair<String, String>, ColumnSt
row.add(String.valueOf(colStatsMeta == null ? "N/A" : colStatsMeta.jobType));
row.add(String.valueOf(colStatsMeta == null ? "N/A" : colStatsMeta.queriedTimes));
row.add(String.valueOf(p.second.updatedTime));
row.add(String.valueOf(colStatsMeta == null ? "N/A" : colStatsMeta.updatedRows));
row.add(String.valueOf(colStatsMeta == null ? "N/A" : colStatsMeta.rowCount));
result.add(row);
});
return new ShowResultSet(getMetaData(), result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,6 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti
rowsToTruncate += partition.getBaseIndex().getRowCount();
}
} else {
rowsToTruncate = olapTable.getRowCount();
for (Partition partition : olapTable.getPartitions()) {
// If need absolutely correct, should check running txn here.
// But if the txn is in prepare state, cann't known which partitions had load data.
Expand All @@ -3125,6 +3124,7 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti
}
origPartitions.put(partition.getName(), partition.getId());
partitionsDistributionInfo.put(partition.getId(), partition.getDistributionInfo());
rowsToTruncate += partition.getBaseIndex().getRowCount();
}
}
// if table currently has no partitions, this sql like empty command and do nothing, should return directly.
Expand Down Expand Up @@ -3285,10 +3285,8 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti
if (truncateEntireTable) {
// Drop the whole table stats after truncate the entire table
Env.getCurrentEnv().getAnalysisManager().dropStats(olapTable);
} else {
// Update the updated rows in table stats after truncate some partitions.
Env.getCurrentEnv().getAnalysisManager().updateUpdatedRows(updateRecords);
}
Env.getCurrentEnv().getAnalysisManager().updateUpdatedRows(updateRecords);
LOG.info("finished to truncate table {}, partitions: {}", tblRef.getName().toSql(), tblRef.getPartitionNames());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ public class SessionVariable implements Serializable, Writable {

public static final String ENABLE_AUTO_ANALYZE = "enable_auto_analyze";

public static final String ENABLE_AUTO_ANALYZE_INTERNAL_CATALOG = "enable_auto_analyze_internal_catalog";

public static final String AUTO_ANALYZE_TABLE_WIDTH_THRESHOLD = "auto_analyze_table_width_threshold";

public static final String FASTER_FLOAT_CONVERT = "faster_float_convert";
Expand Down Expand Up @@ -1492,6 +1494,11 @@ public void setEnableLeftZigZag(boolean enableLeftZigZag) {
flag = VariableMgr.GLOBAL)
public boolean enableAutoAnalyze = true;

@VariableMgr.VarAttr(name = ENABLE_AUTO_ANALYZE_INTERNAL_CATALOG,
description = {"临时参数,收否自动收集所有内表", "Temp variable, enable to auto collect all OlapTable."},
flag = VariableMgr.GLOBAL)
public boolean enableAutoAnalyzeInternalCatalog = false;

@VariableMgr.VarAttr(name = AUTO_ANALYZE_TABLE_WIDTH_THRESHOLD,
description = {"参与自动收集的最大表宽度,列数多于这个参数的表不参与自动收集",
"Maximum table width to enable auto analyze, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ public enum ScheduleType {
@SerializedName("endTime")
public long endTime;

@SerializedName("emptyJob")
public final boolean emptyJob;
@SerializedName("rowCount")
public final long rowCount;

@SerializedName("updateRows")
public final long updateRows;
/**
*
* Used to store the newest partition version of tbl when creating this job.
Expand All @@ -206,7 +209,8 @@ public AnalysisInfo(long jobId, long taskId, List<Long> taskIds, long catalogId,
long lastExecTimeInMs, long timeCostInMs, AnalysisState state, ScheduleType scheduleType,
boolean isExternalTableLevelTask, boolean partitionOnly, boolean samplingPartition,
boolean isAllPartition, long partitionCount, CronExpression cronExpression, boolean forceFull,
boolean usingSqlForPartitionColumn, long tblUpdateTime, boolean emptyJob, boolean userInject) {
boolean usingSqlForPartitionColumn, long tblUpdateTime, long rowCount, boolean userInject,
long updateRows) {
this.jobId = jobId;
this.taskId = taskId;
this.taskIds = taskIds;
Expand Down Expand Up @@ -242,8 +246,9 @@ public AnalysisInfo(long jobId, long taskId, List<Long> taskIds, long catalogId,
this.forceFull = forceFull;
this.usingSqlForPartitionColumn = usingSqlForPartitionColumn;
this.tblUpdateTime = tblUpdateTime;
this.emptyJob = emptyJob;
this.rowCount = rowCount;
this.userInject = userInject;
this.updateRows = updateRows;
}

@Override
Expand Down Expand Up @@ -285,7 +290,9 @@ public String toString() {
}
sj.add("forceFull: " + forceFull);
sj.add("usingSqlForPartitionColumn: " + usingSqlForPartitionColumn);
sj.add("emptyJob: " + emptyJob);
sj.add("rowCount: " + rowCount);
sj.add("userInject: " + userInject);
sj.add("updateRows: " + updateRows);
return sj.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public class AnalysisInfoBuilder {
private boolean forceFull;
private boolean usingSqlForPartitionColumn;
private long tblUpdateTime;
private boolean emptyJob;
private long rowCount;
private boolean userInject;
private long updateRows;

public AnalysisInfoBuilder() {
}
Expand Down Expand Up @@ -101,8 +102,9 @@ public AnalysisInfoBuilder(AnalysisInfo info) {
forceFull = info.forceFull;
usingSqlForPartitionColumn = info.usingSqlForPartitionColumn;
tblUpdateTime = info.tblUpdateTime;
emptyJob = info.emptyJob;
rowCount = info.rowCount;
userInject = info.userInject;
updateRows = info.updateRows;
}

public AnalysisInfoBuilder setJobId(long jobId) {
Expand Down Expand Up @@ -265,8 +267,8 @@ public AnalysisInfoBuilder setTblUpdateTime(long tblUpdateTime) {
return this;
}

public AnalysisInfoBuilder setEmptyJob(boolean emptyJob) {
this.emptyJob = emptyJob;
public AnalysisInfoBuilder setRowCount(long rowCount) {
this.rowCount = rowCount;
return this;
}

Expand All @@ -275,12 +277,17 @@ public AnalysisInfoBuilder setUserInject(boolean userInject) {
return this;
}

public AnalysisInfoBuilder setUpdateRows(long updateRows) {
this.updateRows = updateRows;
return this;
}

public AnalysisInfo build() {
return new AnalysisInfo(jobId, taskId, taskIds, catalogId, dbId, tblId, colToPartitions, partitionNames,
colName, indexId, jobType, analysisMode, analysisMethod, analysisType, samplePercent,
sampleRows, maxBucketNum, periodTimeInMs, message, lastExecTimeInMs, timeCostInMs, state, scheduleType,
externalTableLevelTask, partitionOnly, samplingPartition, isAllPartition, partitionCount,
cronExpression, forceFull, usingSqlForPartitionColumn, tblUpdateTime, emptyJob, userInject);
cronExpression, forceFull, usingSqlForPartitionColumn, tblUpdateTime, rowCount, userInject, updateRows);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ public synchronized void rowCountDone(BaseAnalysisTask task) {
protected void markOneTaskDone() {
if (queryingTask.isEmpty()) {
try {
writeBuf();
updateTaskState(AnalysisState.FINISHED, "Cost time in sec: "
+ (System.currentTimeMillis() - start) / 1000);
flushBuffer();
} finally {
deregisterJob();
}
} else if (buf.size() >= StatisticsUtil.getInsertMergeCount()) {
writeBuf();
flushBuffer();
}
}

Expand All @@ -115,7 +113,7 @@ public void updateTaskState(AnalysisState state, String msg) {
}
}

protected void writeBuf() {
protected void flushBuffer() {
if (killed) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ public AnalysisInfo buildAnalysisJobInfo(AnalyzeTblStmt stmt) throws DdlExceptio
infoBuilder.setColToPartitions(colToPartitions);
infoBuilder.setTaskIds(Lists.newArrayList());
infoBuilder.setTblUpdateTime(table.getUpdateTime());
infoBuilder.setEmptyJob(table instanceof OlapTable && table.getRowCount() == 0);
long rowCount = table.getRowCount();
infoBuilder.setRowCount(rowCount);
TableStatsMeta tableStatsStatus = findTableStatsStatus(table.getId());
infoBuilder.setUpdateRows(tableStatsStatus == null ? 0 : tableStatsStatus.updatedRows.get());
return infoBuilder.build();
}

Expand Down Expand Up @@ -569,7 +572,7 @@ public void updateTableStats(AnalysisInfo jobInfo) {
}
TableStatsMeta tableStats = findTableStatsStatus(tbl.getId());
if (tableStats == null) {
updateTableStatsStatus(new TableStatsMeta(jobInfo.emptyJob ? 0 : tbl.getRowCount(), jobInfo, tbl));
updateTableStatsStatus(new TableStatsMeta(jobInfo.rowCount, jobInfo, tbl));
} else {
tableStats.update(jobInfo, tbl);
logCreateTableStats(tableStats);
Expand Down Expand Up @@ -802,7 +805,7 @@ private BaseAnalysisTask createTask(AnalysisInfo analysisInfo) throws DdlExcepti
analysisInfo.dbId, analysisInfo.tblId);
return table.createAnalysisTask(analysisInfo);
} catch (Throwable t) {
LOG.warn("Failed to find table", t);
LOG.warn("Failed to create task.", t);
throw new DdlException("Failed to create task", t);
}
}
Expand Down Expand Up @@ -1141,10 +1144,12 @@ public boolean canSample(TableIf table) {


public void updateColumnUsedInPredicate(Set<Slot> slotReferences) {
LOG.info("Add slots to high priority queues.");
updateColumn(slotReferences, highPriorityColumns);
}

public void updateQueriedColumn(Collection<Slot> slotReferences) {
LOG.info("Add slots to mid priority queues.");
updateColumn(slotReferences, midPriorityColumns);
}

Expand All @@ -1164,6 +1169,8 @@ protected void updateColumn(Collection<Slot> slotReferences, Queue<HighPriorityC
if (catalog != null) {
queue.offer(new HighPriorityColumn(catalog.getId(), database.getId(),
table.getId(), optionalColumn.get().getName()));
LOG.info("Offer column " + table.getName() + "(" + table.getId() + ")."
+ optionalColumn.get().getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ public class ColStatsMeta {
@SerializedName("trigger")
public JobType jobType;

public ColStatsMeta(long updatedTime, AnalysisMethod analysisMethod,
AnalysisType analysisType, JobType jobType, long queriedTimes) {
@SerializedName("updatedRows")
public long updatedRows;

@SerializedName("rowCount")
public long rowCount;

public ColStatsMeta(long updatedTime, AnalysisMethod analysisMethod, AnalysisType analysisType, JobType jobType,
long queriedTimes, long rowCount, long updatedRows) {
this.updatedTime = updatedTime;
this.analysisMethod = analysisMethod;
this.analysisType = analysisType;
this.jobType = jobType;
this.queriedTimes.addAndGet(queriedTimes);
}

public void clear() {
updatedTime = 0;
this.updatedRows = updatedRows;
this.rowCount = rowCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public OlapAnalysisTask(AnalysisInfo info) {

public void doExecute() throws Exception {
Set<String> partitionNames = info.colToPartitions.get(info.colName);
if ((info.emptyJob && info.analysisMethod.equals(AnalysisInfo.AnalysisMethod.SAMPLE))
if ((info.rowCount == 0 && info.analysisMethod.equals(AnalysisInfo.AnalysisMethod.SAMPLE))
|| partitionNames == null || partitionNames.isEmpty()) {
if (partitionNames == null) {
LOG.warn("Table {}.{}.{}, partitionNames for column {} is null. ColToPartitions:[{}]",
Expand Down
Loading