diff --git a/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.spec.ts b/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.spec.ts index 1abadc425f82..2a31e42af915 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.spec.ts +++ b/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.spec.ts @@ -20,19 +20,20 @@ describe("Create index name", () => { { name: "one parameter no space", query: "CREATE INDEX ON t(i) STORING (k)", - expected: "CREATE INDEX IF NOT EXISTS t_i_rec_idx ON t(i) STORING (k)", + expected: + "CREATE INDEX IF NOT EXISTS t_i_storing_rec_idx ON t(i) STORING (k)", }, { name: "two parameters", query: "CREATE INDEX ON t (i, j) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_i_j_rec_idx ON t (i, j) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_i_j_storing_rec_idx ON t (i, j) STORING (k)", }, { name: "one parameter, one expression", query: "CREATE INDEX ON t (i, (j + k)) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_i_expr_rec_idx ON t (i, (j + k)) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_i_expr_storing_rec_idx ON t (i, (j + k)) STORING (k)", }, { name: "one parameter, one expression no parenthesis", @@ -43,7 +44,7 @@ describe("Create index name", () => { name: "two expressions", query: "CREATE INDEX ON t ((i+l), (j + k)) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_expr_expr1_rec_idx ON t ((i+l), (j + k)) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_expr_expr1_storing_rec_idx ON t ((i+l), (j + k)) STORING (k)", }, { name: "one expression, one parameter", @@ -54,19 +55,19 @@ describe("Create index name", () => { name: "two expressions, one parameter", query: "CREATE INDEX ON t ((i + l), (j + k), a) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_expr_expr1_a_rec_idx ON t ((i + l), (j + k), a) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_expr_expr1_a_storing_rec_idx ON t ((i + l), (j + k), a) STORING (k)", }, { name: "invalid expression, missing )", query: "CREATE INDEX ON t ((i + l, (j + k), a) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_expr_expr1_expr2_rec_idx ON t ((i + l, (j + k), a) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_expr_expr1_expr2_storing_rec_idx ON t ((i + l, (j + k), a) STORING (k)", }, { name: "invalid expression, extra )", query: "CREATE INDEX ON t ((i + l)), (j + k), a) STORING (k)", expected: - "CREATE INDEX IF NOT EXISTS t_expr_rec_idx ON t ((i + l)), (j + k), a) STORING (k)", + "CREATE INDEX IF NOT EXISTS t_expr_storing_rec_idx ON t ((i + l)), (j + k), a) STORING (k)", }, ]; diff --git a/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx b/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx index ae5779903df7..b5a816f0a6da 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx +++ b/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx @@ -256,8 +256,12 @@ export function createIdxName(statement: string): string { idxName += "_" + value; } } - - idxName += "_rec_idx"; + const suffix = + statement.indexOf("STORING") >= 0 ? "_storing_rec_idx" : "_rec_idx"; + // 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; return statement.replace( "CREATE INDEX ON ",