@@ -175,26 +175,34 @@ const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
175175const createIndexRecommendationsQuery : SchemaInsightQuery < CreateIndexRecommendationsResponse > =
176176 {
177177 name : "CreateIndex" ,
178- query : `SELECT
179- encode(fingerprint_id, 'hex') AS fingerprint_id,
180- metadata ->> 'db' AS db,
181- metadata ->> 'query' AS query,
182- metadata ->> 'querySummary' as querySummary,
183- metadata ->> 'implicitTxn' AS implicitTxn,
184- index_recommendations
185- FROM (
186- SELECT
187- fingerprint_id,
188- statistics -> 'statistics' ->> 'lastExecAt' as lastExecAt,
189- metadata,
190- index_recommendations,
191- row_number() over(
192- PARTITION BY
193- fingerprint_id
194- ORDER BY statistics -> 'statistics' ->> 'lastExecAt' DESC
195- ) AS rank
196- FROM crdb_internal.statement_statistics WHERE aggregated_ts >= now() - INTERVAL '1 week')
197- WHERE rank=1 AND array_length(index_recommendations,1) > 0;` ,
178+ query : `
179+ SELECT
180+ encode(fingerprint_id, 'hex') AS fingerprint_id,
181+ metadata ->> 'db' AS db,
182+ metadata ->> 'query' AS query,
183+ metadata ->> 'querySummary' as querySummary,
184+ metadata ->> 'implicitTxn' AS implicitTxn,
185+ index_recommendations
186+ FROM
187+ (
188+ SELECT
189+ fingerprint_id,
190+ statistics -> 'statistics' ->> 'lastExecAt' as lastExecAt,
191+ metadata,
192+ index_recommendations,
193+ row_number() over(
194+ PARTITION BY fingerprint_id
195+ ORDER BY
196+ statistics -> 'statistics' ->> 'lastExecAt' DESC
197+ ) AS rank
198+ FROM
199+ crdb_internal.statement_statistics
200+ WHERE
201+ aggregated_ts >= now() - INTERVAL '1 week'
202+ )
203+ WHERE
204+ rank = 1 AND array_length(index_recommendations, 1) > 0;
205+ ` ,
198206 toSchemaInsight : createIndexRecommendationsToSchemaInsight ,
199207 } ;
200208
0 commit comments