Insights proposed index wrong SQL statement
Describe the problem
Creating an index fails:
The error (from network tab):
{"error":{"code":"42601","message":"parsing statement 1: at or near \"_\": syntax error","detail":"source SQL:\nCREATE INDEX IF NOT EXISTS \"offers\"_\"startdate\"_storing_rec_idx ON whatsuper_tst.\"Offers\".\"Offers\" (\"StartDate\") STORING (\"Name\", \"SubcategoryId\", \"SupermarketId\", \"PriceShort\", \"PriceOld\", \"PriceLabel\", \"PriceUnit\", \"ExtraText\", \"ImageUrl\", \"ImageUrlOriginal\", \"EndDate\", \"MetadataId\", \"NeedsReview\", \"Hidden\", \"ScraperRunId\")\n ^\n--\nCREATE INDEX IF NOT EXISTS \"offers\"_\"startdate\"_storing_rec_idx ON whatsuper_tst.\"Offers\".\"Offers\" (\"StartDate\") STORING (\"Name\", \"SubcategoryId\", \"SupermarketId\", \"PriceShort\", \"PriceOld\", \"PriceLabel\", \"PriceUnit\", \"ExtraText\", \"ImageUrl\", \"ImageUrlOriginal\", \"EndDate\", \"MetadataId\", \"NeedsReview\", \"Hidden\", \"ScraperRunId\")","hint":"try \\h CREATE INDEX","severity":"ERROR","source":{"file":"lexer.go","line":404,"function":"Error"}}}
To Reproduce
This happens when applying a suggested index.
If possible, provide steps to reproduce the behavior:
- Go to insights
- Go to schema insights
- filter on insight typoe "create index"
- Click "create index"
Expected behavior The index is created
Additional data / screenshots Replace index is broken too, but I'm not sure if it's related (didn't look into it, but I assume it is).
Generated SQL:
CREATE INDEX IF NOT EXISTS "offers"_"startdate"_storing_rec_idx ON whatsuper_tst."Offers"."Offers" ("StartDate") STORING ("Name", "SubcategoryId", "SupermarketId", "PriceShort", "PriceOld", "PriceLabel", "PriceUnit", "ExtraText", "ImageUrl", "ImageUrlOriginal", "EndDate", "MetadataId", "NeedsReview", "Hidden", "ScraperRunId");
The issue is caused by the double quotes around offers and startdate. This is a valid SQL statement:
CREATE INDEX IF NOT EXISTS offers_startdate_storing_rec_idx ON whatsuper_tst."Offers"."Offers" ("StartDate") STORING ("Name", "SubcategoryId", "SupermarketId", "PriceShort", "PriceOld", "PriceLabel", "PriceUnit", "ExtraText", "ImageUrl", "ImageUrlOriginal", "EndDate", "MetadataId", "NeedsReview", "Hidden", "ScraperRunId");
Environment:
- CockroachDB version: v23.2.1
- Server OS: Debian 12, running the docker container
cockroachdb/cockroach:v23.2.1 - Client app: dashboard
Hello, I am Blathers. I am here to help you get the issue triaged.
Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.
I have CC'd a few people who may be able to assist you:
- @cockroachdb/sql-foundations (found keywords: SQL statement)
If we have not gotten back to your issue within a few business days, you can try the following:
- Join our community slack channel and ask on #cockroachdb.
- Try find someone from here if you know they worked closely on the area and CC them.
:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.
Some additional context:
- It appears that part of index creation statement is built on FE: https://github.com/cockroachdb/cockroach/blob/178be57bb7a77af0cb87932a9a63c6eec424ed62/pkg/ui/workspaces/cluster-ui/src/insights/indexActionBtn.tsx#L215-L227
- Index recommendation from
crdb_internal.cluster_execution_insightssuggests an index name with.(dots) which is not allowed if not wrapped with quotes. - Could reproduce similar issue when suggested index should be created on table with name like
"t2.1"
Assume that logic on UI should be reduced to consume CREATE INDEX... query as is from the server.