Skip to content

Commit 326a559

Browse files
committed
cluster-ui: format create idx recs query for schema insights page
Epic: none Release note: None
1 parent 509f8c8 commit 326a559

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,34 @@ const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
175175
const 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

Comments
 (0)