Skip to content

Commit

Permalink
[improvement](statistics)Use key column id to query column statistic …
Browse files Browse the repository at this point in the history
…table. (#28885) (#29293)

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.
  • Loading branch information
Jibing-Li authored Dec 29, 2023
1 parent e444348 commit c60eb77
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,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}"
Expand Down Expand Up @@ -359,12 +355,11 @@ public static Map<String, Set<String>> fetchColAndPartsForStats(long tblId) {

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) {
Expand Down

0 comments on commit c60eb77

Please sign in to comment.