Skip to content

Commit

Permalink
cherrypick: [release/2.16.0] fix: column does not exist (#11927)
Browse files Browse the repository at this point in the history
* fix: column does not exist

(cherry picked from commit 7d27794)

* chore: add more tests

(cherry picked from commit a36bfdb)

* Update backend/plugin/advisor/catalog/walk_through_for_mysql.go

(cherry picked from commit f50020d)

* Update backend/plugin/advisor/catalog/walk_through_for_mysql.go

(cherry picked from commit d61c55b)

---------

Co-authored-by: Azusain <azusaings@gmail.com>
Co-authored-by: p0ny <p0uy@outlook.com>
  • Loading branch information
3 people committed May 7, 2024
1 parent 92574c8 commit 2594e1e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
68 changes: 68 additions & 0 deletions backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions backend/plugin/advisor/catalog/walk_through_for_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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:
Expand Down

0 comments on commit 2594e1e

Please sign in to comment.