Skip to content

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

fix: mysqlv2 create index (#9493)

zll600df9e7f5d5b08
diff --git a/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml
index daca0e730c..37453232a0 100644
--- a/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml
+++ b/backend/plugin/advisor/catalog/test/mysqlv2_walk_through.yaml
@@ -7,7 +7,7 @@
err:
type: 201
content: Database `other` is not the current database `test`
- line: 0
+ line: 2
payload: null
- statement: |-
CREATE TABLE `test`.`t1` (a INT);
@@ -15,8 +15,8 @@
ignore_case_sensitive: false
want: |-
{
- "name": "test",
- "schemas": [
+ "name": "test",
+ "schemas": [
{}
]
}
@@ -30,7 +30,7 @@
err:
type: 301
content: Table `t1` already exists
- line: 1
+ line: 3
payload: null
- statement: |-
CREATE TABLE t1(a INT);
@@ -40,7 +40,7 @@
err:
type: 302
content: Table `t2` does not exist
- line: 0
+ line: 2
payload: null
- statement: |-
CREATE TABLE t1 (a INT);
@@ -48,18 +48,18 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -74,7 +74,7 @@
err:
type: 201
content: Database `another` is not the current database `test`
- line: 0
+ line: 1
payload: null
- statement: |-
-- this is comment
@@ -93,12 +93,12 @@
ignore_case_sensitive: false
want: |-
{
- "name": "test",
- "schemas": [
+ "name": "test",
+ "schemas": [
{}
],
- "characterSet": "utf8mb4",
- "collation": "utf8mb4_polish_ci"
+ "characterSet": "utf8mb4",
+ "collation": "utf8mb4_polish_ci"
}
err: null
- statement: |-
@@ -114,22 +114,22 @@
ignore_case_sensitive: false
want: |-
{
- "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": "c",
- "position": 2,
- "type": "varchar"
+ "name": "c",
+ "position": 2,
+ "type": "varchar"
}
]
}
@@ -152,67 +152,68 @@
ignore_case_sensitive: false
want: |-
{
- "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": "b",
- "position": 2,
- "nullable": true,
- "type": "int"
+ "name": "b",
+ "position": 2,
+ "nullable": true,
+ "type": "int"
},
{
- "name": "c",
- "position": 3,
- "type": "varchar"
+ "name": "c",
+ "position": 3,
+ "type": "varchar"
},
{
- "name": "d",
- "position": 4,
- "type": "geometry"
+ "name": "d",
+ "position": 4,
+ "type": "geometry"
}
],
- "indexes": [
+ "indexes": [
{
- "name": "ftk1",
- "expressions": [
+ "name": "ftk1",
+ "expressions": [
"c"
],
- "type": "FULLTEXT",
- "visible": true
+ "type": "FULLTEXT",
+ "visible": true
},
{
- "name": "idx1",
- "expressions": [
+ "name": "idx1",
+ "expressions": [
"a"
],
- "type": "BTREE"
+ "type": "BTREE"
},
{
- "name": "sk1",
- "expressions": [
+ "name": "sk1",
+ "expressions": [
"d"
],
- "type": "SPATIAL",
- "visible": true
+ "type": "SPATIAL",
+ "visible": true
},
{
- "name": "uk1",
- "expressions": [
+ "name": "uk1",
+ "expressions": [
"b"
],
- "type": "BTREE",
- "visible": true
+ "type": "BTREE",
+ "unique": true,
+ "visible": true
}
]
}
@@ -229,7 +230,7 @@
err:
type: 507
content: All parts of a SPATIAL index must be NOT NULL, but `a` is nullable
- line: 0
+ line: 2
payload: null
- statement: |-
CREATE TABLE t1(
@@ -243,49 +244,49 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -303,23 +304,23 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -342,42 +343,42 @@
ignore_case_sensitive: false
want: |-
{
- "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
}
]
}
@@ -394,7 +395,7 @@
err:
type: 406
content: Invalid default value for column `a`
- line: 0
+ line: 2
payload: null
- statement: |-
CREATE TABLE t1(a INT);
@@ -405,7 +406,7 @@
err:
type: 407
content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default value
- line: 1
+ line: 3
payload: null
- statement: |-
CREATE TABLE t1(a INT);
@@ -414,18 +415,18 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -447,30 +448,30 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -492,30 +493,30 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -532,18 +533,18 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -562,7 +563,7 @@
err:
type: 404
content: There can be only one auto column for table `t1`
- line: 0
+ line: 1
payload: null
- statement: CREATE TABLE tvx SELECT (x,z) FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS v(x,y,z);
ignore_case_sensitive: false
@@ -570,7 +571,7 @@
err:
type: 303
content: Disallow the CREATE TABLE AS statement but "CREATE TABLE tvx SELECT (x,z) FROM (VALUES ROW(1,3,5), ROW(2,4,6)) AS v(x,y,z);" uses
- line: 0
+ line: 1
payload: null
- statement: |-
CREATE TABLE t1(a int);
@@ -580,7 +581,7 @@
err:
type: 303
content: Disallow the CREATE TABLE AS statement but "CREATE TABLE t2 (b INT) SELECT a FROM t1;" uses
- line: 0
+ line: 2
payload: null
- statement: |-
CREATE TABLE t1(
@@ -590,29 +591,29 @@
ignore_case_sensitive: false
want: |-
{
- "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"
}
]
}
@@ -635,78 +636,78 @@
ignore_case_sensitive: false
want: |-
{
- "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
}
]
}
@@ -760,70 +761,70 @@
ignore_case_sensitive: false
want: |-
{
- "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.go
index 53745d48d6..0ea31ba9a3 100644
--- a/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.go
+++ b/backend/plugin/advisor/catalog/walk_through_for_mysql_v2.go
@@ -35,6 +35,7 @@ type mysqlV2Listener struct {
*mysql.BaseMySQLParserListener
baseLine int
+ lineNumber int
text string
databaseState *DatabaseState
err *WalkThroughError
@@ -42,6 +43,7 @@ type mysqlV2Listener struct {
func (l *mysqlV2Listener) EnterQuery(ctx *mysql.QueryContext) {
l.text = ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)
+ l.lineNumber = l.baseLine + ctx.GetStart().GetLine()
}
func (d *DatabaseState) mysqlV2ChangeState(in *mysqlparser.ParseResult) (err *WalkThroughError) {
@@ -67,6 +69,9 @@ func (d *DatabaseState) mysqlV2ChangeState(in *mysqlparser.ParseResult) (err *Wa
}
antlr.ParseTreeWalkerDefault.Walk(listener, in.Tree)
if listener.err != nil {
+ if listener.err.Line == 0 {
+ listener.err.Line = listener.lineNumber
+ }
return listener.err
}
return nil
@@ -415,7 +420,8 @@ func (l *mysqlV2Listener) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
isSpatial = true
tp = SpatialName
case mysql.MySQLParserINDEX_SYMBOL:
- case mysql.MySQLParserUNIQUE_SYMBOL:
+ }
+ if ctx.UNIQUE_SYMBOL() != nil {
unique = true
}