Skip to content

Commit f7af5dc

Browse files
committed
ui: fix bug where "Drop Unused Index" recommendations are not populated on...
... Schema Insights When hard refreshing on the Schema Index tab of the insights page, "Drop Unused Index" recommendations don't populate. This is happening due to a race condition in db console, where db console needs cluster settings from the redux store to query for unused indexes. On a hard refresh, the cluster settings aren't in the redux store when querying for these indexes, so it uses the default cluster setting. To fix, the query no longer depends on cluster settings from the reduxstore. Instead, thequery joins on crdb_internal.cluster_settings. Epic: CC-30965 Fixes: CC-31265 Release note (ui change): Fix bug where "Drop Unused Index" recommendations are not populated on the schema index page.
1 parent e2c5563 commit f7af5dc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
InsightType,
99
recommendDropUnusedIndex,
1010
} from "../insights";
11-
import { HexStringToInt64String, indexUnusedDuration } from "../util";
11+
import { HexStringToInt64String } from "../util";
1212

1313
import { QuoteIdentifier } from "./safesql";
1414
import {
@@ -142,8 +142,7 @@ function createIndexRecommendationsToSchemaInsight(
142142
// and want to return the most used ones as a priority.
143143
const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
144144
name: "DropIndex",
145-
query: (csIndexUnusedDuration: string) => {
146-
csIndexUnusedDuration = csIndexUnusedDuration ?? indexUnusedDuration;
145+
query: (_: string) => {
147146
return `SELECT * FROM (SELECT us.table_id,
148147
us.index_id,
149148
us.last_read,
@@ -154,14 +153,16 @@ const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
154153
t.parent_id as database_id,
155154
t.database_name,
156155
t.schema_name,
157-
'${csIndexUnusedDuration}' as unused_threshold,
158-
'${csIndexUnusedDuration}'::interval as interval_threshold,
156+
cs.value as unused_threshold,
157+
cs.value::interval as interval_threshold,
159158
now() - COALESCE(us.last_read AT TIME ZONE 'UTC', COALESCE(ti.created_at, '0001-01-01')) as unused_interval
160159
FROM "".crdb_internal.index_usage_statistics AS us
161160
JOIN "".crdb_internal.table_indexes as ti
162161
ON us.index_id = ti.index_id AND us.table_id = ti.descriptor_id
163162
JOIN "".crdb_internal.tables as t
164163
ON t.table_id = ti.descriptor_id and t.name = ti.descriptor_name
164+
JOIN "".crdb_internal.cluster_settings cs
165+
ON cs.variable = 'sql.index_recommendation.drop_unused_duration'
165166
WHERE t.database_name != 'system' AND ti.is_unique IS false)
166167
WHERE unused_interval > interval_threshold
167168
ORDER BY total_reads DESC;`;

0 commit comments

Comments
 (0)