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: index recommendations properly handle quoted table names #122117

Merged
merged 1 commit into from
May 9, 2024
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,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