Skip to content

Commit

Permalink
Merge pull request #122120 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-121731

release-24.1: ui: index recommendations properly handle quoted table names
  • Loading branch information
abarganier authored Apr 11, 2024
2 parents ff79199 + 6348d46 commit cf15a22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ describe("Create index name", () => {
expected:
"CREATE INDEX IF NOT EXISTS t_expr_storing_rec_idx ON t ((i + l)), (j + k), a) STORING (k)",
},
{
name: "handles table names containing quotes, doesn't include quotes in idx name",
query:
'CREATE INDEX ON defaultdb.public."offers"."startdate" (n) STORING (b);',
expected:
'CREATE INDEX IF NOT EXISTS startdate_n_storing_rec_idx ON defaultdb.public."offers"."startdate" (n) STORING (b);',
},
{
name: "handles table and column names containing quotes & whitespace, doesn't include quotes in idx name",
query: 'CREATE INDEX ON "my table" ("my col");',
expected:
'CREATE INDEX IF NOT EXISTS my_table_my_col_rec_idx ON "my table" ("my col");',
},
{
name: "handles quotes within quotes, doesn't include quotes in idx name",
query: 'CREATE INDEX ON "my""table" ("with""quote");',
expected:
'CREATE INDEX IF NOT EXISTS mytable_withquote_rec_idx ON "my""table" ("with""quote");',
},
];

for (let i = 0; i < testCases.length; i++) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ export function createIdxName(statement: string): string {
// The table name is fully qualified at this point, but we don't need the full name,
// so just use the last value (also an index name can't have ".")
const idxNameArr = idxName.split(".");
idxName = idxNameArr[idxNameArr.length - 1].replace(/\s/g, "_") + suffix;
idxName =
idxNameArr[idxNameArr.length - 1].replace(/"/g, "").replace(/\s/g, "_") +
suffix;

return statement.replace(
"CREATE INDEX ON ",
Expand Down

0 comments on commit cf15a22

Please sign in to comment.