Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(mysqlv2): support drop index (#9472)
zll600108e9f3b1c4d
diff --git a/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yamlindex 8c18701dfd..0ca26744aa 100644--- a/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml+++ b/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml@@ -1,3 +1,40 @@+- statement: |-+ CREATE TABLE t1(+ a INT PRIMARY KEY,+ c VARCHAR(255) NOT NULL+ );+ ALTER TABLE t1 ADD INDEX idx1 (c);+ CREATE FULLTEXT INDEX ftk1 ON t1 (c);+ DROP INDEX `PRIMARY` ON t1;+ DROP INDEX idx1 ON t1;+ DROP INDEX ftk1 ON t1;+ ignore_case_sensitive: false+ want: |-+ {+ "name": "test",+ "schemas": [+ {+ "tables": [+ {+ "name": "t1",+ "columns": [+ {+ "name": "a",+ "position": 1,+ "type": "int"+ },+ {+ "name": "c",+ "position": 2,+ "type": "varchar"+ }+ ]+ }+ ]+ }+ ]+ }+ err: null- statement: |-CREATE TABLE t1(a INT,@@ -103,49 +140,49 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "type": "int"+ "name": "a",+ "position": 1,+ "type": "int"},{- "name": "b",- "position": 2,- "nullable": true,- "type": "int"+ "name": "b",+ "position": 2,+ "nullable": true,+ "type": "int"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "primary": true,+ "visible": true},{- "name": "uk1",- "expressions": [+ "name": "uk1",+ "expressions": ["b"],- "type": "BTREE",- "unique": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "visible": true}],- "engine": "MyISAM",- "collation": "utf8mb4_unicode_ci",- "comment": "t1 table"+ "engine": "MyISAM",+ "collation": "utf8mb4_unicode_ci",+ "comment": "t1 table"}]}@@ -163,23 +200,23 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "type": "int"+ "name": "a",+ "position": 1,+ "type": "int"},{- "name": "b",- "position": 2,- "nullable": true,- "type": "int"+ "name": "b",+ "position": 2,+ "nullable": true,+ "type": "int"}]}@@ -202,42 +239,42 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t2",- "columns": [+ "name": "t2",+ "columns": [{- "name": "a",- "position": 1,- "nullable": true,- "type": "int"+ "name": "a",+ "position": 1,+ "nullable": true,+ "type": "int"},{- "name": "b",- "position": 2,- "nullable": true,- "type": "int"+ "name": "b",+ "position": 2,+ "nullable": true,+ "type": "int"}],- "indexes": [+ "indexes": [{- "name": "idx2",- "expressions": [+ "name": "idx2",+ "expressions": ["b"],- "type": "BTREE"+ "type": "BTREE"},{- "name": "uk_b",- "expressions": [+ "name": "uk_b",+ "expressions": ["b"],- "type": "BTREE",- "unique": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "visible": true}]}@@ -274,18 +311,18 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "nullable": true,- "type": "blob"+ "name": "a",+ "position": 1,+ "nullable": true,+ "type": "blob"}]}@@ -307,30 +344,30 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [- {- "name": "a",- "position": 1,- "default": "1",- "nullable": true,- "type": "int"+ "name": "t1",+ "columns": [+ {+ "name": "a",+ "position": 1,+ "default": "1",+ "nullable": true,+ "type": "int"},{- "name": "d",- "position": 2,- "nullable": true,- "type": "text"+ "name": "d",+ "position": 2,+ "nullable": true,+ "type": "text"},{- "name": "c",- "position": 3,- "type": "int"+ "name": "c",+ "position": 3,+ "type": "int"}]}@@ -352,30 +389,30 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "e",- "position": 1,- "nullable": true,- "type": "int"+ "name": "e",+ "position": 1,+ "nullable": true,+ "type": "int"},{- "name": "f",- "position": 2,- "nullable": true,- "type": "text"+ "name": "f",+ "position": 2,+ "nullable": true,+ "type": "text"},{- "name": "c",- "position": 3,- "nullable": true,- "type": "int"+ "name": "c",+ "position": 3,+ "nullable": true,+ "type": "int"}]}@@ -392,18 +429,18 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t3",- "columns": [+ "name": "t3",+ "columns": [{- "name": "a",- "position": 1,- "nullable": true,- "type": "int"+ "name": "a",+ "position": 1,+ "nullable": true,+ "type": "int"}]}@@ -450,29 +487,29 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "nullable": true,- "type": "int"+ "name": "a",+ "position": 1,+ "nullable": true,+ "type": "int"}]},{- "name": "t2",- "columns": [+ "name": "t2",+ "columns": [{- "name": "a",- "position": 1,- "nullable": true,- "type": "int"+ "name": "a",+ "position": 1,+ "nullable": true,+ "type": "int"}]}@@ -495,78 +532,78 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "type": "int"+ "name": "a",+ "position": 1,+ "type": "int"},{- "name": "b",- "position": 2,- "default": "1",- "type": "int"+ "name": "b",+ "position": 2,+ "default": "1",+ "type": "int"},{- "name": "c",- "position": 3,- "nullable": true,- "type": "int"+ "name": "c",+ "position": 3,+ "nullable": true,+ "type": "int"},{- "name": "d",- "position": 4,- "type": "varchar"+ "name": "d",+ "position": 4,+ "type": "varchar"},{- "name": "e",- "position": 5,- "nullable": true,- "type": "varchar"+ "name": "e",+ "position": 5,+ "nullable": true,+ "type": "varchar"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "primary": true,+ "visible": true},{- "name": "d",- "expressions": [+ "name": "d",+ "expressions": ["d","e"],- "type": "FULLTEXT"+ "type": "FULLTEXT"},{- "name": "idx1",- "expressions": [+ "name": "idx1",+ "expressions": ["c"],- "type": "BTREE",- "visible": true+ "type": "BTREE",+ "visible": true},{- "name": "uk1",- "expressions": [+ "name": "uk1",+ "expressions": ["b","c"],- "type": "BTREE",- "unique": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "visible": true}]}@@ -620,70 +657,70 @@ignore_case_sensitive: falsewant: |-{- "name": "test",- "schemas": [+ "name": "test",+ "schemas": [{- "tables": [+ "tables": [{- "name": "t1",- "columns": [+ "name": "t1",+ "columns": [{- "name": "a",- "position": 1,- "default": "1",- "type": "int"+ "name": "a",+ "position": 1,+ "default": "1",+ "type": "int"},{- "name": "b",- "position": 2,- "nullable": true,- "type": "int"+ "name": "b",+ "position": 2,+ "nullable": true,+ "type": "int"},{- "name": "c",- "position": 3,- "default": "NULL",- "type": "varchar",- "comment": "column c"+ "name": "c",+ "position": 3,+ "default": "NULL",+ "type": "varchar",+ "comment": "column c"},{- "name": "e",- "position": 4,- "nullable": true,- "type": "int"+ "name": "e",+ "position": 4,+ "nullable": true,+ "type": "int"},{- "name": "f",- "position": 5,- "type": "varchar",- "collation": "utf8mb4_polish_ci"+ "name": "f",+ "position": 5,+ "type": "varchar",+ "collation": "utf8mb4_polish_ci"},{- "name": "g",- "position": 6,- "type": "varchar",- "characterSet": "utf8mb4"+ "name": "g",+ "position": 6,+ "type": "varchar",+ "characterSet": "utf8mb4"}],- "indexes": [+ "indexes": [{- "name": "PRIMARY",- "expressions": [+ "name": "PRIMARY",+ "expressions": ["a"],- "type": "BTREE",- "unique": true,- "primary": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "primary": true,+ "visible": true},{- "name": "b",- "expressions": [+ "name": "b",+ "expressions": ["b"],- "type": "BTREE",- "unique": true,- "visible": true+ "type": "BTREE",+ "unique": true,+ "visible": true}]}diff --git a/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.go b/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.goindex 2c68ef6f9c..37fa5d84fd 100644--- a/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.go+++ b/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.go@@ -368,6 +368,28 @@ func (l *mysqlV2Listener) EnterAlterTable(ctx *mysql.AlterTableContext) {}}+// EnterDropIndex is called when production dropIndex is entered.+func (l *mysqlV2Listener) EnterDropIndex(ctx *mysql.DropIndexContext) {+ if ctx.TableRef() == nil {+ return+ }+ databaseName, tableName := mysqlparser.NormalizeMySQLTableRef(ctx.TableRef())+ table, err := l.databaseState.mysqlV2FindTableState(databaseName, tableName, true /* createIncompleteTAble */)+ if err != nil {+ l.err = err+ return+ }++ if ctx.IndexRef() == nil {+ return+ }++ _, _, indexName := mysqlparser.NormalizeIndexRef(ctx.IndexRef())+ if err := table.dropIndex(l.databaseState.ctx, indexName); err != nil {+ l.err = err+ }+}+func (l *mysqlV2Listener) EnterCreateIndex(ctx *mysql.CreateIndexContext) {if ctx.CreateIndexTarget() == nil || ctx.CreateIndexTarget().TableRef() == nil {return