Skip to content

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

fix: column does not exist (#11926)

Azusain352846299757
diff --git a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
index 37453232a0..8161a8d140 100644
--- a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
+++ b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
@@ -833,3 +833,71 @@
]
}
err: null
+- statement: |-
+ CREATE TABLE t1(
+ id int,
+ name varchar(255),
+ key idx_name(name)
+ );
+ create table t2 (
+ id int,
+ t1_name varchar(255),
+ constraint fk_t1_name foreign key (t1_name) references t1 (name)
+ );
+ alter table t2 drop foreign key fk_t1_name;
+ ignore_case_sensitive: false
+ want: |-
+ {
+ "name": "test",
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "t1",
+ "columns": [
+ {
+ "name": "id",
+ "position": 1,
+ "nullable": true,
+ "type": "int"
+ },
+ {
+ "name": "name",
+ "position": 2,
+ "nullable": true,
+ "type": "varchar"
+ }
+ ],
+ "indexes": [
+ {
+ "name": "idx_name",
+ "expressions": [
+ "name"
+ ],
+ "type": "BTREE",
+ "visible": true
+ }
+ ]
+ },
+ {
+ "name": "t2",
+ "columns": [
+ {
+ "name": "id",
+ "position": 1,
+ "nullable": true,
+ "type": "int"
+ },
+ {
+ "name": "t1_name",
+ "position": 2,
+ "nullable": true,
+ "type": "varchar"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ err: null
diff --git a/backend/plugin/advisor/catalog/walk_through_for_mysql.go b/backend/plugin/advisor/catalog/walk_through_for_mysql.go
index cae0b2c27c..7e3f83b273 100644
--- a/backend/plugin/advisor/catalog/walk_through_for_mysql.go
+++ b/backend/plugin/advisor/catalog/walk_through_for_mysql.go
@@ -297,9 +297,12 @@ func (l *mysqlListener) EnterAlterTable(ctx *mysql.AlterTableContext) {
return
}
}
- // drop column.
+ // drop column or key.
case item.DROP_SYMBOL() != nil && item.ALTER_SYMBOL() == nil:
switch {
+ // drop foreign key.
+ // we do not deal with DROP FOREIGN KEY statements.
+ case item.FOREIGN_SYMBOL() != nil && item.KEY_SYMBOL() != nil:
// drop column.
case item.ColumnInternalRef() != nil:
columnName := mysqlparser.NormalizeMySQLColumnInternalRef(item.ColumnInternalRef())
@@ -320,9 +323,6 @@ func (l *mysqlListener) EnterAlterTable(ctx *mysql.AlterTableContext) {
l.err = err
return
}
- // drop foreign key.
- case item.FOREIGN_SYMBOL() != nil && item.KEY_SYMBOL() != nil:
- // we do not deal with DROP FOREIGN KEY statements.
}
// modify column.
case item.MODIFY_SYMBOL() != nil && item.ColumnInternalRef() != nil: