Skip to content

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

fix: add mysqlwip walkthrough (#9084)

zll600711f75549180
diff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.go
index 98b92dc5c6..9cd470850b 100644
--- a/backend/plugin/advisor/catalog/walk_through.go
+++ b/backend/plugin/advisor/catalog/walk_through.go
@@ -208,6 +208,10 @@ func (e *WalkThroughError) Error() string {
// WalkThrough will collect the catalog schema in the databaseState as it walks through the stmt.
func (d *DatabaseState) WalkThrough(stmt string) error {
switch d.dbType {
+ // only for mysqlwip test.
+ case storepb.Engine_ENGINE_UNSPECIFIED:
+ err := d.mysqlWalkThrough(stmt)
+ return err
case storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
err := d.mysqlWalkThrough(stmt)
return err
diff --git a/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml b/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml
index bc9f08e43c..1202469b93 100644
--- a/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/database_drop_empty_database.yaml
@@ -6,11 +6,3 @@
content: Database `test` is not allowed to drop if not empty
line: 1
details: ""
-- statement: DROP DATABASE IF EXISTS bbdev;
- want:
- - status: WARN
- code: 702
- title: database.drop-empty-database
- content: Database `bbdev` that is trying to be deleted is not the current database `test`
- line: 1
- details: ""
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_column.yaml b/backend/plugin/advisor/mysqlwip/test/naming_column.yaml
index b4bb8b140e..59ec77061e 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_column.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_column.yaml
@@ -41,7 +41,7 @@
details: ""
- statement: |
ALTER TABLE tech_book RENAME COLUMN id TO creator_id;
- ALTER TABLE tech_book RENAME COLUMN id TO gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx;
+ ALTER TABLE tech_book RENAME COLUMN creator_id TO gbhzmtchhsjzyrhdroxmyouwloxqezowdvhcbqalqcgqhfbjnvmhwrbggezmzeusx;
want:
- status: WARN
code: 302
@@ -64,7 +64,9 @@
content: '`book`.`creatorId` mismatches column naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'
line: 7
details: ""
-- statement: ALTER TABLE tech_book CHANGE COLUMN id creator_id int;
+- statement: |-
+ CREATE TABLE book (id INT);
+ ALTER TABLE book CHANGE COLUMN id creator_id int;
want:
- status: SUCCESS
code: 0
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml b/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml
index b2576623e9..d71879232b 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_column_auto_increment.yaml
@@ -14,35 +14,29 @@
content: '`book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'
line: 1
details: ""
-- statement: |
- CREATE TABLE tech_book (name VARCHAR(255));
- ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT;
+- statement: ALTER TABLE tech_book ADD COLUMN a int AUTO_INCREMENT;
want:
- status: WARN
code: 307
title: naming.column.auto-increment
content: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'
- line: 2
+ line: 1
details: ""
-- statement: |
- CREATE TABLE tech_book (name VARCHAR(255));
- ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT;
+- statement: ALTER TABLE tech_book CHANGE COLUMN id a int AUTO_INCREMENT;
want:
- status: WARN
code: 307
title: naming.column.auto-increment
content: '`tech_book`.`a` mismatches auto_increment column naming convention, naming format should be "^id$"'
- line: 2
+ line: 1
details: ""
-- statement: |
- CREATE TABLE tech_book (price INT);
- ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT;
+- statement: ALTER TABLE tech_book MODIFY COLUMN name int AUTO_INCREMENT;
want:
- status: WARN
code: 307
title: naming.column.auto-increment
content: '`tech_book`.`name` mismatches auto_increment column naming convention, naming format should be "^id$"'
- line: 2
+ line: 1
details: ""
- statement: |
CREATE TABLE book(id int);
@@ -56,7 +50,7 @@
details: ""
- statement: |
CREATE TABLE book(name VARCHAR(255));
- ALTER TABLE tech_book ADD COLUMN id int AUTO_INCREMENT;
+ ALTER TABLE book ADD COLUMN id int AUTO_INCREMENT;
want:
- status: SUCCESS
code: 0
@@ -66,7 +60,7 @@
details: ""
- statement: |
CREATE TABLE book(a INT, name VARCHAR(255));
- ALTER TABLE tech_book CHANGE COLUMN a id int AUTO_INCREMENT;
+ ALTER TABLE book CHANGE COLUMN a id int AUTO_INCREMENT;
want:
- status: SUCCESS
code: 0
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml b/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml
index 8e897bc7ba..eb56823084 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_index_fk.yaml
@@ -1,6 +1,4 @@
-- statement: |
- CREATE TABLE tech_book(id INT);
- ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id);
+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id);
want:
- status: SUCCESS
code: 0
@@ -8,15 +6,13 @@
content: ""
line: 0
details: ""
-- statement: |
- CREATE TABLE tech_book(id INT);
- ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id);
+- statement: ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id);
want:
- status: WARN
code: 305
title: naming.index.fk
content: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `fk_author_id`
- line: 2
+ line: 1
details: ""
- statement: ALTER TABLE tech_book ADD CONSTRAINT rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk FOREIGN KEY (author_id) REFERENCES author (id);
want:
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml b/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml
index 81512d0634..c320c41d51 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_index_idx.yaml
@@ -6,31 +6,27 @@
content: ""
line: 0
details: ""
-- statement: |
- CREATE TABLE tech_book (id INT, name VARCHAR(255));
- CREATE INDEX tech_book_id_name ON tech_book(id, name);
+- statement: CREATE INDEX tech_book_id_name ON tech_book(id, name);
want:
- status: WARN
code: 303
title: naming.index.idx
content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `tech_book_id_name`
- line: 2
+ line: 1
details: ""
-- statement: |
- CREATE TABLE tech_book (id INT, name VARCHAR(255));
- CREATE INDEX afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw ON tech_book(id, name);
+- statement: CREATE INDEX afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw ON tech_book(id, name);
want:
- status: WARN
code: 303
title: naming.index.idx
content: Index `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw` in table `tech_book` mismatches the naming convention, its length should be within 64 characters
- line: 2
+ line: 1
details: ""
- status: WARN
code: 303
title: naming.index.idx
content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw`
- line: 2
+ line: 1
details: ""
- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book_id_name;
want:
@@ -40,19 +36,15 @@
content: ""
line: 0
details: ""
-- statement: |
- CREATE TABLE tech_book (id INT, name VARCHAR(255));
- ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book;
+- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book;
want:
- status: WARN
code: 303
title: naming.index.idx
content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `idx_tech_book`
- line: 2
+ line: 1
details: ""
-- statement: |
- CREATE TABLE tech_book (id INT, name VARCHAR(255));
- ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name);
+- statement: ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name);
want:
- status: SUCCESS
code: 0
@@ -60,15 +52,13 @@
content: ""
line: 0
details: ""
-- statement: |
- CREATE TABLE tech_book (id INT, name VARCHAR(255));
- ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name);
+- statement: ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name);
want:
- status: WARN
code: 303
title: naming.index.idx
content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `tech_book_id_name`
- line: 2
+ line: 1
details: ""
- statement: CREATE TABLE tech_book_copy(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_copy_name (name));
want:
diff --git a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml b/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
index 046cd2c40a..7529feef28 100644
--- a/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/naming_table.yaml
@@ -23,8 +23,8 @@
line: 1
details: ""
- statement: |
- CREATE TABLE tech_book(a INT);
- ALTER TABLE tech_book RENAME TO TechBook;
+ CREATE TABLE book(a INT);
+ ALTER TABLE book RENAME TO TechBook;
want:
- status: WARN
code: 301
@@ -33,8 +33,8 @@
line: 2
details: ""
- statement: |
- CREATE TABLE tech_book(a INT);
- ALTER TABLE tech_book RENAME TO tech_book_copy;
+ CREATE TABLE book(a INT);
+ ALTER TABLE book RENAME TO tech_book_copy;
want:
- status: SUCCESS
code: 0
@@ -43,8 +43,8 @@
line: 0
details: ""
- statement: |
- CREATE TABLE tech_book (a INT);
- RENAME TABLE tech_book TO tech_book_copy, tech_book_copy TO LiteraryBook;
+ CREATE TABLE book (a INT);
+ RENAME TABLE book TO tech_book_copy, tech_book_copy TO LiteraryBook;
want:
- status: WARN
code: 301
@@ -54,8 +54,8 @@
details: ""
- statement: |
CREATE TABLE literary_book(a int);
- CREATE TABLE tech_book(a int);
- RENAME TABLE tech_book TO TechBook, literary_book TO LiteraryBook;
+ CREATE TABLE book(a int);
+ RENAME TABLE book TO TechBook, literary_book TO LiteraryBook;
want:
- status: WARN
code: 301
@@ -71,8 +71,8 @@
details: ""
- statement: |
CREATE TABLE literary_book(a int);
- CREATE TABLE teck_book(a int);
- RENAME TABLE tech_book TO tech_book_copy, literary_book TO literary_book_copy;
+ CREATE TABLE book(a int);
+ RENAME TABLE book TO tech_book_copy, literary_book TO literary_book_copy;
want:
- status: SUCCESS
code: 0
diff --git a/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml b/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml
index 59a80b83b4..af1ba35f4c 100644
--- a/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/statement_merge_alter_table.yaml
@@ -8,7 +8,7 @@
details: ""
- statement: |-
ALTER TABLE tech_book ADD COLUMN a int;
- ALTER TABLE tech_book CHANGE COLUMN b c int;
+ ALTER TABLE tech_book CHANGE COLUMN a c int;
want:
- status: WARN
code: 207
@@ -18,7 +18,7 @@
details: ""
- statement: |-
CREATE TABLE t(a int);
- ALTER TABLE tech_book ADD COLUMN a int;
+ ALTER TABLE tech_book ADD COLUMN b int;
ALTER TABLE t ADD COLUMN b int;
ALTER TABLE tech_book MODIFY COLUMN b varchar(255);
want:
diff --git a/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml b/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml
index e579a92a6d..b94741322f 100644
--- a/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/statement_where_require.yaml
@@ -1,6 +1,6 @@
- statement: |
- CREATE TABLE tech_book(id INT);
- INSERT INTO tech_book(id) values (1);
+ CREATE TABLE book(id INT);
+ INSERT INTO book(id) values (1);
want:
- status: SUCCESS
code: 0
@@ -9,30 +9,30 @@
line: 0
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- DELETE FROM tech_book;
+ CREATE TABLE book(id INT);
+ DELETE FROM book;
want:
- status: WARN
code: 202
title: statement.where.require
content: |-
- "DELETE FROM tech_book;" requires WHERE clause
+ "DELETE FROM book;" requires WHERE clause
line: 2
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- UPDATE tech_book SET id = 1;
+ CREATE TABLE book(id INT);
+ UPDATE book SET id = 1;
want:
- status: WARN
code: 202
title: statement.where.require
content: |-
- "UPDATE tech_book SET id = 1;" requires WHERE clause
+ "UPDATE book SET id = 1;" requires WHERE clause
line: 2
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- DELETE FROM tech_book WHERE id > 0;
+ CREATE TABLE book(id INT);
+ DELETE FROM book WHERE id > 0;
want:
- status: SUCCESS
code: 0
@@ -41,8 +41,8 @@
line: 0
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- UPDATE tech_book SET id = 1 WHERE id > 10;
+ CREATE TABLE book(id INT);
+ UPDATE book SET id = 1 WHERE id > 10;
want:
- status: SUCCESS
code: 0
@@ -51,19 +51,19 @@
line: 0
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- SELECT id FROM tech_book;
+ CREATE TABLE book(id INT);
+ SELECT id FROM book;
want:
- status: WARN
code: 202
title: statement.where.require
content: |-
- "SELECT id FROM tech_book;" requires WHERE clause
+ "SELECT id FROM book;" requires WHERE clause
line: 2
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
- SELECT id FROM tech_book WHERE id > 0;
+ CREATE TABLE book(id INT);
+ SELECT id FROM book WHERE id > 0;
want:
- status: SUCCESS
code: 0
@@ -72,12 +72,12 @@
line: 0
details: ""
- statement: |
- CREATE TABLE tech_book(id INT);
+ CREATE TABLE book(id INT);
SELECT id
- FROM tech_book
+ FROM book
WHERE id > (
SELECT max(id)
- FROM tech_book
+ FROM book
);
want:
- status: WARN
@@ -85,10 +85,10 @@
title: statement.where.require
content: |-
"SELECT id
- FROM tech_book
+ FROM book
WHERE id > (
SELECT max(id)
- FROM tech_book
+ FROM book
);" requires WHERE clause
line: 5
details: ""
diff --git a/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml b/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml
index 71984bce8c..5d387953c9 100644
--- a/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/table_require_pk.yaml
@@ -169,13 +169,14 @@
line: 0
details: ""
- statement: |-
+ ALTER TABLE tech_book ADD COLUMN c INT;
ALTER TABLE tech_book DROP COLUMN name, DROP COLUMN id;
want:
- status: WARN
code: 601
title: table.require-pk
content: Table `tech_book` requires PRIMARY KEY
- line: 1
+ line: 2
details: ""
- statement: |-
ALTER TABLE tech_book CHANGE COLUMN id uid int;
diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.go
index 3480b198bd..082bc85f88 100644
--- a/backend/plugin/advisor/sql_review.go
+++ b/backend/plugin/advisor/sql_review.go
@@ -693,6 +693,11 @@ func SQLReviewCheck(statements string, ruleList []*storepb.SQLReviewRule, checkC
finder := checkContext.Catalog.GetFinder()
switch checkContext.DbType {
+ // only for mysqlwip test.
+ case storepb.Engine_ENGINE_UNSPECIFIED:
+ if err := finder.WalkThrough(statements); err != nil {
+ return convertWalkThroughErrorToAdvice(checkContext, err)
+ }
case storepb.Engine_TIDB, storepb.Engine_MYSQL, storepb.Engine_MARIADB, storepb.Engine_POSTGRES, storepb.Engine_OCEANBASE:
if err := finder.WalkThrough(statements); err != nil {
return convertWalkThroughErrorToAdvice(checkContext, err)