[improvement](statistics)Use key column id to query column statistic table. (#28885)

Use id as where predicate to load column statistic cache. This could improve performance, because id is the first order key in column statistics table.
This commit is contained in:
Jibing-Li
2023-12-27 14:38:55 +08:00
committed by GitHub
parent fc6a587352
commit 578a7dadc1

View File

@ -97,10 +97,6 @@ public class StatisticsRepository {
+ " WHERE tbl_id = ${tblId}"
+ " AND part_id IS NOT NULL";
private static final String QUERY_COLUMN_STATISTICS = "SELECT * FROM " + FeConstants.INTERNAL_DB_NAME
+ "." + StatisticConstants.STATISTIC_TBL_NAME + " WHERE "
+ "tbl_id=${tblId} AND idx_id=${idxId} AND col_id='${colId}'";
private static final String QUERY_PARTITION_STATISTICS = "SELECT * FROM " + FeConstants.INTERNAL_DB_NAME
+ "." + StatisticConstants.STATISTIC_TBL_NAME + " WHERE "
+ " ${inPredicate}"
@ -357,12 +353,11 @@ public class StatisticsRepository {
public static List<ResultRow> loadColStats(long tableId, long idxId, String colName) {
Map<String, String> params = new HashMap<>();
params.put("tblId", String.valueOf(tableId));
params.put("idxId", String.valueOf(idxId));
params.put("colId", StatisticsUtil.escapeSQL(colName));
String id = constructId(tableId, idxId, colName);
params.put("id", StatisticsUtil.escapeSQL(id));
return StatisticsUtil.execStatisticQuery(new StringSubstitutor(params)
.replace(QUERY_COLUMN_STATISTICS));
.replace(FETCH_COLUMN_STATISTIC_TEMPLATE));
}
public static List<ResultRow> loadPartStats(Collection<StatisticsCacheKey> keys) {