Skip to content

Commit

Permalink
Merge pull request #93035 from maryliag/backport22.2-92953
Browse files Browse the repository at this point in the history
release-22.2: ui: fix link for index from insights
  • Loading branch information
maryliag authored Dec 5, 2022
2 parents 9530659 + 6bf2431 commit 98ec8e2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type ClusterIndexUsageStatistic = {
database_id: number;
database_name: string;
unused_threshold: string;
schema_name: string;
};

type CreateIndexRecommendationsResponse = {
Expand Down Expand Up @@ -68,12 +69,13 @@ function clusterIndexUsageStatsToSchemaInsight(
results[key] = {
type: "DropIndex",
database: row.database_name,
query: `DROP INDEX ${row.table_name}@${row.index_name};`,
query: `DROP INDEX ${row.schema_name}.${row.table_name}@${row.index_name};`,
indexDetails: {
table: row.table_name,
indexID: row.index_id,
indexName: row.index_name,
lastUsed: result.reason,
schema: row.schema_name,
},
};
}
Expand Down Expand Up @@ -136,6 +138,7 @@ const dropUnusedIndexQuery: SchemaInsightQuery<ClusterIndexUsageStatistic> = {
t.name as table_name,
t.parent_id as database_id,
t.database_name,
t.schema_name,
(SELECT value FROM crdb_internal.cluster_settings WHERE variable = 'sql.index_recommendation.drop_unused_duration') AS unused_threshold
FROM "".crdb_internal.index_usage_statistics AS us
JOIN "".crdb_internal.table_indexes as ti ON us.index_id = ti.index_id AND us.table_id = ti.descriptor_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("recommendDropUnusedIndex", () => {
table_name: "test_table",
database_id: 1,
database_name: "test_db",
schema_name: "public",
unused_threshold: "10h0m0s",
};
it("should not recommend index to be dropped", () => {
Expand All @@ -49,6 +50,7 @@ describe("recommendDropUnusedIndex", () => {
table_name: "test_table",
database_id: 1,
database_name: "test_db",
schema_name: "public",
unused_threshold: "10h0m0s",
};
it("should recommend index to be dropped with the reason that the index is never used", () => {
Expand All @@ -68,6 +70,7 @@ describe("recommendDropUnusedIndex", () => {
table_name: "test_table",
database_id: 1,
database_name: "test_db",
schema_name: "public",
unused_threshold: "0h30m0s",
};
it("should recommend index to be dropped with the reason that it has exceeded the configured index unuse duration", () => {
Expand All @@ -92,6 +95,7 @@ describe("recommendDropUnusedIndex", () => {
table_name: "test_table",
database_id: 1,
database_name: "test_db",
schema_name: "public",
unused_threshold: "10h0m0s",
};
it("should not recommend index to be dropped", () => {
Expand All @@ -113,6 +117,7 @@ describe("recommendDropUnusedIndex", () => {
table_name: "test_table",
database_id: 1,
database_name: "test_db",
schema_name: "public",
unused_threshold: "0h30m0s",
};
it("should recommend index to be dropped with the reason that it has exceeded the configured index unuse duration", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const SchemaInsightsPropsFixture: SchemaInsightsViewProps = {
table: "table_name",
indexID: 1,
indexName: "index_name",
schema: "public",
lastUsed:
"This index has not been used and can be removed for better write performance.",
},
Expand All @@ -30,6 +31,7 @@ export const SchemaInsightsPropsFixture: SchemaInsightsViewProps = {
table: "table_name2",
indexID: 2,
indexName: "index_name2",
schema: "public",
lastUsed:
"This index has not been used in over 9 days, 5 hours, and 3 minutes and can be removed for better write performance.",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/workspaces/cluster-ui/src/insights/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export interface InsightRecommendation {

export interface indexDetails {
table: string;
schema: string;
indexID: number;
indexName: string;
lastUsed?: string;
Expand Down
15 changes: 9 additions & 6 deletions pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ function typeCell(value: string): React.ReactElement {

function descriptionCell(
insightRec: InsightRecommendation,
disableStmtLink?: boolean,
disableStmtLink: boolean,
isCockroachCloud: boolean,
): React.ReactElement {
const clusterSettingsLink = (
<>
Expand All @@ -91,6 +92,11 @@ function descriptionCell(
insightRec.execution?.statement,
insightRec.execution?.summary,
);

const indexLink = isCockroachCloud
? `databases/${insightRec.database}/${insightRec.indexDetails?.schema}/${insightRec.indexDetails?.table}/${insightRec.indexDetails?.indexName}`
: `database/${insightRec.database}/table/${insightRec.indexDetails?.table}/index/${insightRec.indexDetails?.indexName}`;

switch (insightRec.type) {
case "CreateIndex":
case "ReplaceIndex":
Expand Down Expand Up @@ -130,10 +136,7 @@ function descriptionCell(
<>
<div className={cx("description-item")}>
<span className={cx("label-bold")}>Index: </span>{" "}
<Link
to={`database/${insightRec.database}/table/${insightRec.indexDetails.table}/index/${insightRec.indexDetails.indexName}`}
className={cx("table-link")}
>
<Link to={indexLink} className={cx("table-link")}>
{insightRec.indexDetails.indexName}
</Link>
</div>
Expand Down Expand Up @@ -296,7 +299,7 @@ export function makeInsightsColumns(
name: "details",
title: insightsTableTitles.details(),
cell: (item: InsightRecommendation) =>
descriptionCell(item, disableStmtLink),
descriptionCell(item, disableStmtLink, isCockroachCloud),
sort: (item: InsightRecommendation) => item.type,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("SchemaInsights sagas", () => {
table: "test_table",
indexName: "test_idx",
indexID: 1,
schema: "public",
lastUsed: "2022-08-22T22:30:02Z",
},
},
Expand Down

0 comments on commit 98ec8e2

Please sign in to comment.