From 5dd5006168ce3ccf93e311aefe4f586eefca3a34 Mon Sep 17 00:00:00 2001 From: Jibing-Li <64681310+Jibing-Li@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:58:22 +0800 Subject: [PATCH] [improvement](statistics)Use real base index id to fetch stats cache. (#36914) For historical reason, statistics tables use -1 for OlapTable base index id. This brings many if/else branch for stats calculate. This pr is to screen the -1 for Nereids. The stats user could use the real base index id to fetch stats cache. Will do the id translation inside the get cache api. --- .../doris/statistics/StatisticsCache.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java index e8ef250e6743c8..d86e073d9e4001 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java @@ -18,6 +18,8 @@ package org.apache.doris.statistics; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.TableIf; import org.apache.doris.common.ClientPool; import org.apache.doris.common.Config; import org.apache.doris.common.ThreadPoolManager; @@ -79,6 +81,12 @@ public ColumnStatistic getColumnStatistics(long catalogId, long dbId, long tblId if (ctx != null && ctx.getSessionVariable().internalSession) { return ColumnStatistic.UNKNOWN; } + // Need to change base index id to -1 for OlapTable. + try { + idxId = changeBaseIndexId(catalogId, dbId, tblId, idxId); + } catch (Exception e) { + return ColumnStatistic.UNKNOWN; + } StatisticsCacheKey k = new StatisticsCacheKey(catalogId, dbId, tblId, idxId, colName); try { CompletableFuture> f = columnStatisticsCache.get(k); @@ -91,6 +99,21 @@ public ColumnStatistic getColumnStatistics(long catalogId, long dbId, long tblId return ColumnStatistic.UNKNOWN; } + // Base index id should be set to -1 for OlapTable. Because statistics tables use -1 for base index. + // TODO: Need to use the real index id in statistics table in later version. + private long changeBaseIndexId(long catalogId, long dbId, long tblId, long idxId) { + if (idxId != -1) { + TableIf table = StatisticsUtil.findTable(catalogId, dbId, tblId); + if (table instanceof OlapTable) { + OlapTable olapTable = (OlapTable) table; + if (idxId == olapTable.getBaseIndexId()) { + idxId = -1; + } + } + } + return idxId; + } + public Histogram getHistogram(long ctlId, long dbId, long tblId, String colName) { return getHistogram(ctlId, dbId, tblId, -1, colName).orElse(null); }