Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(tidb): respect IF EXISTS clause in DROP INDEX walk-through (#19410)

Vincent Huangef52f5f3e494
diff --git a/backend/plugin/schema/tidb/testdata/walk_through.yaml b/backend/plugin/schema/tidb/testdata/walk_through.yaml
index 6fc8d4ed8b..378f5c844f 100644
--- a/backend/plugin/schema/tidb/testdata/walk_through.yaml
+++ b/backend/plugin/schema/tidb/testdata/walk_through.yaml
@@ -419,6 +419,36 @@
\ ],\n \"type\": \"BTREE\",\n \"visible\"\
: true\n }\n ]\n }\n ]\n }\n ]\n}"
advice: null
+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\
+ \ SET utf8mb4 NOT NULL UNIQUE\n);\nDROP INDEX IF EXISTS nonexistent on t;"
+ ignore_case_sensitive: false
+ want: "{\n \"name\": \"test\",\n \"schemas\": [\n {\n \"tables\": [\n\
+ \ {\n \"name\": \"t\",\n \"columns\": [\n \
+ \ {\n \"name\": \"a\",\n \"position\": 1,\n \
+ \ \"default\": \"1\",\n \"type\": \"int(11)\"\n },\n\
+ \ {\n \"name\": \"b\",\n \"position\": 2,\n\
+ \ \"type\": \"varchar(200)\",\n \"characterSet\": \"\
+ utf8mb4\"\n }\n ],\n \"indexes\": [\n \
+ \ {\n \"name\": \"PRIMARY\",\n \"expressions\": [\n\
+ \ \"a\"\n ],\n \"type\": \"BTREE\",\n\
+ \ \"unique\": true,\n \"primary\": true,\n \
+ \ \"visible\": true\n },\n {\n \"name\"\
+ : \"b\",\n \"expressions\": [\n \"b\"\n \
+ \ ],\n \"type\": \"BTREE\",\n \"unique\": true,\n\
+ \ \"visible\": true\n }\n ]\n }\n \
+ \ ]\n }\n ]\n}"
+ advice: null
+- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\
+ \ SET utf8mb4 NOT NULL UNIQUE\n);\nDROP INDEX nonexistent on t;"
+ ignore_case_sensitive: false
+ want: ''
+ advice:
+ status: 1
+ code: 809
+ title: index "nonexistent" does not exist in table "t"
+ content: index "nonexistent" does not exist in table "t"
+ startPosition:
+ line: 0
- statement: "CREATE TABLE t(\n a int PRIMARY KEY DEFAULT 1,\n b varchar(200) CHARACTER\
\ SET utf8mb4 NOT NULL UNIQUE\n);\nDROP INDEX b on t;"
ignore_case_sensitive: false
diff --git a/backend/plugin/schema/tidb/walk_through.go b/backend/plugin/schema/tidb/walk_through.go
index 5ed56f8034..e11d0ba83f 100644
--- a/backend/plugin/schema/tidb/walk_through.go
+++ b/backend/plugin/schema/tidb/walk_through.go
@@ -299,6 +299,9 @@ func tidbDropIndex(d *model.DatabaseMetadata, node *tidbast.DropIndexStmt) *stor
}
if err := table.DropIndex(node.IndexName); err != nil {
+ if node.IfExists {
+ return nil
+ }
return &storepb.Advice{
Status: storepb.Advice_ERROR,
Code: code.IndexNotExists.Int32(),