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 @@ -119,6 +119,8 @@ public enum OlapTableState {
WAITING_STABLE
}

public static long ROW_COUNT_BEFORE_REPORT = -1;

private volatile OlapTableState state;

// index id -> index meta
Expand Down Expand Up @@ -1296,10 +1298,10 @@ public long getRowCountForIndex(long indexId, boolean strict) {
if (index == null) {
LOG.warn("Index {} not exist in partition {}, table {}, {}",
indexId, entry.getValue().getName(), id, name);
return -1;
return ROW_COUNT_BEFORE_REPORT;
}
if (strict && !index.getRowCountReported()) {
return -1;
return ROW_COUNT_BEFORE_REPORT;
}
rowCount += index.getRowCount() == -1 ? 0 : index.getRowCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ protected void createAnalyzeJobForTbl(DatabaseIf<? extends TableIf> db,
List<AnalysisInfo> analysisInfos, TableIf table) {
AnalysisMethod analysisMethod = table.getDataSize(true) >= StatisticsUtil.getHugeTableLowerBoundSizeInBytes()
? AnalysisMethod.SAMPLE : AnalysisMethod.FULL;
if (table instanceof OlapTable && analysisMethod.equals(AnalysisMethod.SAMPLE)) {
OlapTable ot = (OlapTable) table;
if (ot.getRowCountForIndex(ot.getBaseIndexId(), true) == OlapTable.ROW_COUNT_BEFORE_REPORT) {
LOG.info("Table {} row count is not fully reported, skip auto analyzing this time.", ot.getName());
return;
}
}
long rowCount = StatisticsUtil.isEmptyTable(table, analysisMethod) ? 0 : table.getRowCount();
AnalysisInfo jobInfo = new AnalysisInfoBuilder()
.setJobId(Env.getCurrentEnv().getNextId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,36 @@ protected boolean canCollect() {

sac.analyzeAll();
}

@Test
public void testCreateAnalyzeJobForTbl() {
StatisticsAutoCollector collector = new StatisticsAutoCollector();
OlapTable table = new OlapTable();
new MockUp<OlapTable>() {
@Mock
public long getDataSize(boolean singleReplica) {
return 100;
}

@Mock
public long getRowCountForIndex(long indexId, boolean strict) {
return -1;
}

@Mock
public boolean isPartitionedTable() {
return false;
}
};
List<AnalysisInfo> infos = Lists.newArrayList();
collector.createAnalyzeJobForTbl(null, infos, table);
Assertions.assertEquals(0, infos.size());
new MockUp<OlapTable>() {
@Mock
public long getRowCountForIndex(long indexId, boolean strict) {
return 100;
}
};
Assertions.assertThrows(NullPointerException.class, () -> collector.createAnalyzeJobForTbl(null, infos, table));
}
}