Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1: ui: drop index with space #100023

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ui/workspaces/cluster-ui/src/api/safesql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SQL implements SQLStringer {
// case sensitive when used in a query. If the input string contains a zero
// byte, the result will be truncated immediately before it.
// Cribbed from https://github.com/lib/pq and Typescript-ified.
function QuoteIdentifier(name: string): string {
export function QuoteIdentifier(name: string): string {
// Use a search regex to replace all occurrences instead of just the first occurrence.
const search = /"/g;
return `"` + name.replace(search, `""`) + `"`;
Expand Down
7 changes: 6 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
recommendDropUnusedIndex,
} from "../insights";
import { HexStringToInt64String } from "../util";
import { QuoteIdentifier } from "./safesql";

// Export for db-console import from clusterUiApi.
export type { InsightRecommendation } from "../insights";
Expand Down Expand Up @@ -72,7 +73,11 @@ function clusterIndexUsageStatsToSchemaInsight(
results[key] = {
type: "DropIndex",
database: row.database_name,
query: `DROP INDEX ${row.schema_name}.${row.table_name}@${row.index_name};`,
query: `DROP INDEX ${QuoteIdentifier(
row.schema_name,
)}.${QuoteIdentifier(row.table_name)}@${QuoteIdentifier(
row.index_name,
)};`,
indexDetails: {
table: row.table_name,
indexID: row.index_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { RecommendationType } from "../indexDetailsPage";
import LoadingError from "../sqlActivity/errorComponent";
import { Loading } from "../loading";
import { UIConfigState } from "../store";
import { QuoteIdentifier } from "../api/safesql";

const cx = classNames.bind(styles);
const booleanSettingCx = classnames.bind(booleanSettingStyles);
Expand Down Expand Up @@ -375,7 +376,9 @@ export class DatabaseTablePage extends React.Component<
const query = indexStat.indexRecommendations.map(recommendation => {
switch (recommendation.type) {
case "DROP_UNUSED":
return `DROP INDEX ${this.props.name}@${indexStat.indexName};`;
return `DROP INDEX ${QuoteIdentifier(
this.props.name,
)}@${QuoteIdentifier(indexStat.indexName)};`;
}
});
if (query.length === 0) {
Expand Down