Skip to content

Commit

Permalink
cluster-ui: format create idx recs query for schema insights page
Browse files Browse the repository at this point in the history
Epic: none

Release note: None
  • Loading branch information
xinhaoz committed Aug 1, 2023
1 parent 509f8c8 commit 326a559
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,34 @@ const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
const createIndexRecommendationsQuery: SchemaInsightQuery<CreateIndexRecommendationsResponse> =
{
name: "CreateIndex",
query: `SELECT
encode(fingerprint_id, 'hex') AS fingerprint_id,
metadata ->> 'db' AS db,
metadata ->> 'query' AS query,
metadata ->> 'querySummary' as querySummary,
metadata ->> 'implicitTxn' AS implicitTxn,
index_recommendations
FROM (
SELECT
fingerprint_id,
statistics -> 'statistics' ->> 'lastExecAt' as lastExecAt,
metadata,
index_recommendations,
row_number() over(
PARTITION BY
fingerprint_id
ORDER BY statistics -> 'statistics' ->> 'lastExecAt' DESC
) AS rank
FROM crdb_internal.statement_statistics WHERE aggregated_ts >= now() - INTERVAL '1 week')
WHERE rank=1 AND array_length(index_recommendations,1) > 0;`,
query: `
SELECT
encode(fingerprint_id, 'hex') AS fingerprint_id,
metadata ->> 'db' AS db,
metadata ->> 'query' AS query,
metadata ->> 'querySummary' as querySummary,
metadata ->> 'implicitTxn' AS implicitTxn,
index_recommendations
FROM
(
SELECT
fingerprint_id,
statistics -> 'statistics' ->> 'lastExecAt' as lastExecAt,
metadata,
index_recommendations,
row_number() over(
PARTITION BY fingerprint_id
ORDER BY
statistics -> 'statistics' ->> 'lastExecAt' DESC
) AS rank
FROM
crdb_internal.statement_statistics
WHERE
aggregated_ts >= now() - INTERVAL '1 week'
)
WHERE
rank = 1 AND array_length(index_recommendations, 1) > 0;
`,
toSchemaInsight: createIndexRecommendationsToSchemaInsight,
};

Expand Down

0 comments on commit 326a559

Please sign in to comment.