From d501d9d4291cbd681ec98fa7e436d9cc43c659b6 Mon Sep 17 00:00:00 2001 From: Monika Singh Date: Wed, 30 Jul 2025 23:25:54 +0800 Subject: [PATCH] fix: Add default time filter to ClickHouse queries to avoid full table scans --- packages/common-utils/src/metadata.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/common-utils/src/metadata.ts b/packages/common-utils/src/metadata.ts index 216b89b21..0f77eafae 100644 --- a/packages/common-utils/src/metadata.ts +++ b/packages/common-utils/src/metadata.ts @@ -244,9 +244,10 @@ export class Metadata { strategy = 'lowCardinalityKeys'; } + // If no metricName is provided, apply default time filter to avoid full table scan const where = metricName ? chSql`WHERE MetricName=${{ String: metricName }}` - : ''; + : chSql`WHERE TimestampTime > (now() - toIntervalDay(7))`; let sql: ChSql; if (strategy === 'groupUniqArrayArray') { sql = chSql`SELECT groupUniqArrayArray(${{ Int32: maxKeys }})(${{