Skip to content

Commit 4444320

Browse files
[Enhancement] modify histogram_statistic cache expire-update logical
Signed-off-by: stephen <[email protected]>
1 parent aee1d8f commit 4444320

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/CachedStatisticStorage.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ public void refreshColumnStatistics(Table table, List<String> columns, boolean i
161161
}
162162
}
163163

164+
@Override
165+
public void refreshHistogramStatistics(Table table, List<String> columns, boolean isSync) {
166+
Preconditions.checkState(table != null);
167+
168+
if (StatisticUtils.statisticTableBlackListCheck(table.getId()) ||
169+
!StatisticUtils.checkStatisticTableStateNormal()) {
170+
return;
171+
}
172+
173+
List<ColumnStatsCacheKey> cacheKeys = new ArrayList<>();
174+
long tableId = table.getId();
175+
for (String column : columns) {
176+
cacheKeys.add(new ColumnStatsCacheKey(tableId, column));
177+
}
178+
179+
try {
180+
ColumnHistogramStatsCacheLoader loader = new ColumnHistogramStatsCacheLoader();
181+
CompletableFuture<Map<ColumnStatsCacheKey, Optional<Histogram>>> future =
182+
loader.asyncLoadAll(cacheKeys, statsCacheRefresherExecutor);
183+
if (isSync) {
184+
Map<ColumnStatsCacheKey, Optional<Histogram>> result = future.get();
185+
histogramCache.synchronous().putAll(result);
186+
} else {
187+
future.whenComplete((res, e) -> histogramCache.synchronous().putAll(res));
188+
}
189+
} catch (Exception e) {
190+
LOG.warn("Failed to refresh histogram", e);
191+
}
192+
}
193+
164194
@Override
165195
public List<ConnectorTableColumnStats> getConnectorTableStatistics(Table table, List<String> columns) {
166196
Preconditions.checkState(table != null);

fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ default void refreshColumnStatistics(Table table, List<String> columns, boolean
4141
default void refreshMultiColumnStatistics(Long tableId) {
4242
}
4343

44+
default void refreshHistogramStatistics(Table table, List<String> columns, boolean isSync) {
45+
}
46+
4447
/**
4548
* Overwrite the statistics of `targetPartition` with `sourcePartition`
4649
*/

fe/fe-core/src/main/java/com/starrocks/statistic/AnalyzeMgr.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,7 @@ public void refreshHistogramStatisticsCache(Long dbId, Long tableId, List<String
381381
return;
382382
}
383383

384-
GlobalStateMgr.getCurrentState().getStatisticStorage().expireHistogramStatistics(table.getId(), columns);
385-
if (async) {
386-
GlobalStateMgr.getCurrentState().getStatisticStorage().getHistogramStatistics(table, columns);
387-
} else {
388-
GlobalStateMgr.getCurrentState().getStatisticStorage().getHistogramStatisticsSync(table, columns);
389-
}
384+
GlobalStateMgr.getCurrentState().getStatisticStorage().refreshHistogramStatistics(table, columns, !async);
390385
}
391386

392387
public void replayRemoveHistogramStatsMeta(HistogramStatsMeta histogramStatsMeta) {

0 commit comments

Comments
 (0)