Skip to content

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

fix: consider case sensitive in walkthrough (#8644)

h3n4l78beda2b75d1
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 3e74e54e6b..566c9e6bd7 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -999,7 +999,7 @@ func (s *Service) sqlAdviceForFile(
if fileInfo.repoInfo.project.SchemaChangeType == api.ProjectSchemaChangeTypeSDL {
advisorMode = advisor.SyntaxModeSDL
}
- catalog, err := s.store.NewCatalog(ctx, database.UID, instance.Engine, advisorMode)
+ catalog, err := s.store.NewCatalog(ctx, database.UID, instance.Engine, store.IgnoreDatabaseAndTableCaseSensitive(instance), advisorMode)
if err != nil {
return nil, errors.Errorf("Failed to get catalog for database %v with error: %v", database.UID, err)
}
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 7d80f48f63..3f0ab54ec1 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1642,7 +1642,7 @@ func (s *SQLService) sqlReviewCheck(ctx context.Context, statement string, envir
}
}
- catalog, err := s.store.NewCatalog(ctx, database.UID, instance.Engine, advisor.SyntaxModeNormal)
+ catalog, err := s.store.NewCatalog(ctx, database.UID, instance.Engine, store.IgnoreDatabaseAndTableCaseSensitive(instance), advisor.SyntaxModeNormal)
if err != nil {
return advisor.Error, nil, status.Errorf(codes.Internal, "Failed to create a catalog: %v", err)
}
diff --git a/backend/plugin/advisor/catalog/finder.go b/backend/plugin/advisor/catalog/finder.go
index 7316a75cb9..20377b0eff 100644
--- a/backend/plugin/advisor/catalog/finder.go
+++ b/backend/plugin/advisor/catalog/finder.go
@@ -23,12 +23,21 @@ type FinderContext struct {
// EngineType is the engine type for database engine.
EngineType storepb.Engine
+
+ // Ignore case sensitive is the policy for identifier name comparison case-sensitive.
+ // It has different behavior for different database engine.
+ // MySQL:
+ // This controls the following identifier comparisons:
+ // Database, Table
+ IgnoreCaseSensitive bool
}
// Copy returns the deep copy.
func (ctx *FinderContext) Copy() *FinderContext {
return &FinderContext{
- CheckIntegrity: ctx.CheckIntegrity,
+ CheckIntegrity: ctx.CheckIntegrity,
+ EngineType: ctx.EngineType,
+ IgnoreCaseSensitive: ctx.IgnoreCaseSensitive,
}
}
@@ -43,7 +52,7 @@ func NewFinder(database *storepb.DatabaseSchemaMetadata, ctx *FinderContext) *Fi
return &Finder{Origin: newDatabaseState(database, ctx), Final: newDatabaseState(database, ctx)}
}
-// NewEmptyFinder creates a finder with empty databse.
+// NewEmptyFinder creates a finder with empty database.
func NewEmptyFinder(ctx *FinderContext) *Finder {
return &Finder{Origin: newDatabaseState(&storepb.DatabaseSchemaMetadata{}, ctx), Final: newDatabaseState(&storepb.DatabaseSchemaMetadata{}, ctx)}
}
diff --git a/backend/plugin/advisor/catalog/state.go b/backend/plugin/advisor/catalog/state.go
index 8ca18cf3d4..48b2027b5b 100644
--- a/backend/plugin/advisor/catalog/state.go
+++ b/backend/plugin/advisor/catalog/state.go
@@ -30,7 +30,7 @@ func newDatabaseState(d *storepb.DatabaseSchemaMetadata, context *FinderContext)
for _, view := range schema.Views {
for _, dependentColumn := range view.DependentColumns {
if schemaState, exist := database.schemaSet[dependentColumn.Schema]; exist {
- if tableState, exist := schemaState.tableSet[dependentColumn.Table]; exist {
+ if tableState, exist := schemaState.getTable(dependentColumn.Table); exist {
tableState.dependentView[fmt.Sprintf("%q.%q", schema.Name, view.Name)] = true
if columnState, exist := tableState.columnSet[dependentColumn.Column]; exist {
columnState.dependentView[fmt.Sprintf("%q.%q", schema.Name, view.Name)] = true
@@ -204,7 +204,7 @@ func (d *DatabaseState) FindIndex(find *IndexFind) (string, *IndexState) {
if !exists {
return "", nil
}
- table, exists := schema.tableSet[find.TableName]
+ table, exists := schema.getTable(find.TableName)
if !exists {
return "", nil
}
@@ -243,7 +243,7 @@ func (d *DatabaseState) FindPrimaryKey(find *PrimaryKeyFind) *IndexState {
continue
}
for _, table := range schema.tableSet {
- if table.name != find.TableName {
+ if !compareIdentifier(table.name, find.TableName, schema.ctx.IgnoreCaseSensitive) {
continue
}
for _, index := range table.indexSet {
@@ -269,7 +269,7 @@ func (d *DatabaseState) CountColumn(count *ColumnCount) int {
if !exists {
return 0
}
- table, exists := schema.tableSet[count.TableName]
+ table, exists := schema.getTable(count.TableName)
if !exists {
return 0
}
@@ -295,7 +295,7 @@ func (d *DatabaseState) FindColumn(find *ColumnFind) *ColumnState {
if !exists {
return nil
}
- table, exists := schema.tableSet[find.TableName]
+ table, exists := schema.getTable(find.TableName)
if !exists {
return nil
}
@@ -318,7 +318,7 @@ func (d *DatabaseState) FindTable(find *TableFind) *TableState {
if !exists {
return nil
}
- table, exists := schema.tableSet[find.TableName]
+ table, exists := schema.getTable(find.TableName)
if !exists {
return nil
}
@@ -340,7 +340,7 @@ type SchemaState struct {
}
func (d *SchemaState) Index(tableIndexFind *TableIndexFind) *IndexStateMap {
- table, exists := d.tableSet[tableIndexFind.TableName]
+ table, exists := d.getTable(tableIndexFind.TableName)
if !exists {
return nil
}
diff --git a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
index a48f3a720d..20d6e2a582 100644
--- a/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
+++ b/backend/plugin/advisor/catalog/test/mysql_walk_through.yaml
@@ -1,20 +1,23 @@
- statement: CREATE TABLE t(a date default '');
+ ignore_case_sensitive: false
want: null
err:
type: 407
- content: '[types:1292]Incorrect datetime value: '''''
+ content: "[types:1292]Incorrect datetime value: ''"
line: 1
payload: null
- statement: |-
CREATE TABLE t(a TEXT);
- ALTER TABLE t ALTER COLUMN a SET DEFAULT '1';
+ ALTER TABLE T ALTER COLUMN a SET DEFAULT '1';
+ ignore_case_sensitive: true
want: null
err:
type: 407
content: BLOB, TEXT, GEOMETRY or JSON column `a` can't have a default value
line: 2
payload: null
-- statement: ' CREATE TABLE t(a TEXT DEFAULT ''1'')'
+- statement: " CREATE TABLE t(a TEXT DEFAULT '1')"
+ ignore_case_sensitive: false
want: null
err:
type: 407
@@ -24,34 +27,39 @@
- statement: |-
CREATE TABLE t(a INT NOT NULL);
ALTER TABLE t ALTER COLUMN a SET DEFAULT NULL;
+ ignore_case_sensitive: false
want: null
err:
type: 406
content: Invalid default value for column `a`
line: 2
payload: null
-- statement: ' CREATE TABLE t(a INT NOT NULL DEFAULT NULL)'
+- statement: " CREATE TABLE t(a INT NOT NULL DEFAULT NULL)"
+ ignore_case_sensitive: false
want: null
err:
type: 406
content: Invalid default value for column `a`
line: 1
payload: null
-- statement: ' CREATE TABLE t(a int ON UPDATE NOW())'
+- statement: " CREATE TABLE t(a int ON UPDATE NOW())"
+ ignore_case_sensitive: false
want: null
err:
type: 405
content: Column `a` use ON UPDATE but is not DATETIME or TIMESTAMP
line: 1
payload: null
-- statement: ' CREATE TABLE t(a int auto_increment, b int auto_increment);'
+- statement: " CREATE TABLE t(a int auto_increment, b int auto_increment);"
+ ignore_case_sensitive: false
want: null
err:
type: 404
content: There can be only one auto column for table `t`
line: 1
payload: null
-- statement: ' CREATE TABLE t as select * from t1;'
+- statement: " CREATE TABLE t as select * from t1;"
+ ignore_case_sensitive: false
want: null
err:
type: 303
@@ -59,6 +67,7 @@
line: 1
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tCREATE INDEX idx_c on t(c);\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -66,6 +75,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t MODIFY COLUMN c int;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -73,6 +83,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t CHANGE COLUMN c aa int;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -80,6 +91,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t DROP COLUMN c;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -87,6 +99,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -94,6 +107,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t RENAME COLUMN c TO cc;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -101,6 +115,7 @@
line: 3
payload: null
- statement: "\n\t\t\t\tCREATE TABLE t(a int, b int); \n\t\t\t\tALTER TABLE t ALTER COLUMN c DROP DEFAULT;\n\t\t\t"
+ ignore_case_sensitive: false
want: null
err:
type: 402
@@ -110,15 +125,16 @@
- statement: |-
ALTER DATABASE CHARACTER SET = utf8mb4;
ALTER DATABASE test COLLATE utf8mb4_polish_ci;
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: utf8mb4
collation: utf8mb4_polish_ci
extensions: []
@@ -137,229 +153,230 @@
FULLTEXT (b, d) WITH PARSER ngram INVISIBLE
);
CREATE TABLE t_copy like t;
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t
- columns:
- - name: a
- position: 1
- default:
- value: "1"
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: varchar(200)
- characterset: utf8mb4
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: c
- position: 3
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: This is a comment
- classification: ""
- usercomment: ""
- - name: d
- position: 4
- default: null
- nullable: true
- type: varchar(10)
- characterset: ""
- collation: utf8mb4_polish_ci
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- - name: b
- expressions:
- - b
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_2
- expressions:
- - b
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: b_3
- expressions:
- - b
- - c
- - d
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_4
- expressions:
- - b
- - d
- type: FULLTEXT
- unique: false
- primary: false
- visible: false
- comment: ""
- - name: idx_a
- expressions:
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- - name: t_copy
- columns:
- - name: a
- position: 1
- default:
- value: "1"
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: varchar(200)
- characterset: utf8mb4
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: c
- position: 3
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: This is a comment
- classification: ""
- usercomment: ""
- - name: d
- position: 4
- default: null
- nullable: true
- type: varchar(10)
- characterset: ""
- collation: utf8mb4_polish_ci
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- - name: b
- expressions:
- - b
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_2
- expressions:
- - b
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: b_3
- expressions:
- - b
- - c
- - d
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_4
- expressions:
- - b
- - d
- type: FULLTEXT
- unique: false
- primary: false
- visible: false
- comment: ""
- - name: idx_a
- expressions:
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t
+ columns:
+ - name: a
+ position: 1
+ default:
+ value: "1"
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: varchar(200)
+ characterset: utf8mb4
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: c
+ position: 3
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: This is a comment
+ classification: ""
+ usercomment: ""
+ - name: d
+ position: 4
+ default: null
+ nullable: true
+ type: varchar(10)
+ characterset: ""
+ collation: utf8mb4_polish_ci
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ - name: b
+ expressions:
+ - b
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_2
+ expressions:
+ - b
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_3
+ expressions:
+ - b
+ - c
+ - d
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_4
+ expressions:
+ - b
+ - d
+ type: FULLTEXT
+ unique: false
+ primary: false
+ visible: false
+ comment: ""
+ - name: idx_a
+ expressions:
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ - name: t_copy
+ columns:
+ - name: a
+ position: 1
+ default:
+ value: "1"
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: varchar(200)
+ characterset: utf8mb4
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: c
+ position: 3
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: This is a comment
+ classification: ""
+ usercomment: ""
+ - name: d
+ position: 4
+ default: null
+ nullable: true
+ type: varchar(10)
+ characterset: ""
+ collation: utf8mb4_polish_ci
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ - name: b
+ expressions:
+ - b
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_2
+ expressions:
+ - b
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_3
+ expressions:
+ - b
+ - c
+ - d
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_4
+ expressions:
+ - b
+ - d
+ type: FULLTEXT
+ unique: false
+ primary: false
+ visible: false
+ comment: ""
+ - name: idx_a
+ expressions:
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -377,122 +394,123 @@
UNIQUE (b, c, d),
FULLTEXT (b, d) WITH PARSER ngram INVISIBLE
)
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t
- columns:
- - name: a
- position: 1
- default:
- value: "1"
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: varchar(200)
- characterset: utf8mb4
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: c
- position: 3
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: This is a comment
- classification: ""
- usercomment: ""
- - name: d
- position: 4
- default: null
- nullable: true
- type: varchar(10)
- characterset: ""
- collation: utf8mb4_polish_ci
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- - name: b
- expressions:
- - b
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_2
- expressions:
- - b
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: b_3
- expressions:
- - b
- - c
- - d
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_4
- expressions:
- - b
- - d
- type: FULLTEXT
- unique: false
- primary: false
- visible: false
- comment: ""
- - name: idx_a
- expressions:
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t
+ columns:
+ - name: a
+ position: 1
+ default:
+ value: "1"
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: varchar(200)
+ characterset: utf8mb4
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: c
+ position: 3
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: This is a comment
+ classification: ""
+ usercomment: ""
+ - name: d
+ position: 4
+ default: null
+ nullable: true
+ type: varchar(10)
+ characterset: ""
+ collation: utf8mb4_polish_ci
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ - name: b
+ expressions:
+ - b
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_2
+ expressions:
+ - b
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_3
+ expressions:
+ - b
+ - c
+ - d
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_4
+ expressions:
+ - b
+ - d
+ type: FULLTEXT
+ unique: false
+ primary: false
+ visible: false
+ comment: ""
+ - name: idx_a
+ expressions:
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -505,58 +523,59 @@
b int,
PRIMARY KEY (a, b)
)
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t
- columns:
- - name: a
- position: 1
- default: null
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- - b
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t
+ columns:
+ - name: a
+ position: 1
+ default: null
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ - b
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -567,22 +586,24 @@
CREATE TABLE t1(a int, b int, c int);
CREATE TABLE t2(a int);
DROP TABLE t1, t2
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
datashare: false
servicename: ""
err: null
-- statement: ' DROP TABLE t1, t2'
+- statement: " DROP TABLE t1, t2"
+ ignore_case_sensitive: false
want: null
err:
type: 302
@@ -592,15 +613,16 @@
- statement: |-
CREATE TABLE t(a int);
RENAME TABLE t to other_db.t1
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -610,39 +632,40 @@
- statement: |-
CREATE TABLE t(a int);
RENAME TABLE t to test.t1
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t1
- columns:
- - name: a
- position: 1
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- indexes: []
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t1
+ columns:
+ - name: a
+ position: 1
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes: []
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -653,6 +676,7 @@
-- this is comment
DROP DATABASE test;
CREATE TABLE t(a int);
+ ignore_case_sensitive: false
want: null
err:
type: 202
@@ -684,122 +708,123 @@
ALTER TABLE t_copy ALTER COLUMN a_copy DROP DEFAULT;
ALTER TABLE t_copy RENAME INDEX b TO idx_b;
ALTER TABLE t_copy ALTER INDEX b_3 INVISIBLE;
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t_copy
- columns:
- - name: b
- position: 1
- default: null
- nullable: true
- type: varchar(20)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: a_copy
- position: 2
- default: null
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: a1
- position: 3
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: d_copy
- position: 4
- default: null
- nullable: true
- type: varchar(10)
- characterset: ""
- collation: utf8mb4_polish_ci
- comment: ""
- classification: ""
- usercomment: ""
- - name: e
- position: 5
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: b_3
- expressions:
- - b
- - d_copy
- type: BTREE
- unique: true
- primary: false
- visible: false
- comment: ""
- - name: b_4
- expressions:
- - b
- - d_copy
- type: FULLTEXT
- unique: false
- primary: false
- visible: false
- comment: ""
- - name: idx_a
- expressions:
- - a_copy
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: idx_a_b
- expressions:
- - a_copy
- - b
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: idx_b
- expressions:
- - b
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- engine: INNODB
- collation: utf8mb4_0900_ai_ci
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: This is a table comment
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t_copy
+ columns:
+ - name: b
+ position: 1
+ default: null
+ nullable: true
+ type: varchar(20)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: a_copy
+ position: 2
+ default: null
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: a1
+ position: 3
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: d_copy
+ position: 4
+ default: null
+ nullable: true
+ type: varchar(10)
+ characterset: ""
+ collation: utf8mb4_polish_ci
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: e
+ position: 5
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: b_3
+ expressions:
+ - b
+ - d_copy
+ type: BTREE
+ unique: true
+ primary: false
+ visible: false
+ comment: ""
+ - name: b_4
+ expressions:
+ - b
+ - d_copy
+ type: FULLTEXT
+ unique: false
+ primary: false
+ visible: false
+ comment: ""
+ - name: idx_a
+ expressions:
+ - a_copy
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: idx_a_b
+ expressions:
+ - a_copy
+ - b
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: idx_b
+ expressions:
+ - b
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ engine: INNODB
+ collation: utf8mb4_0900_ai_ci
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: This is a table comment
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -817,122 +842,123 @@
CREATE INDEX b_2 on t(b, a);
CREATE UNIQUE INDEX b_3 on t(b, c, d);
CREATE FULLTEXT INDEX b_4 on t(b, d) WITH PARSER ngram INVISIBLE;
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t
- columns:
- - name: a
- position: 1
- default:
- value: "1"
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: varchar(200)
- characterset: utf8mb4
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: c
- position: 3
- default: null
- nullable: true
- type: int(11)
- characterset: ""
- collation: ""
- comment: This is a comment
- classification: ""
- usercomment: ""
- - name: d
- position: 4
- default: null
- nullable: true
- type: varchar(10)
- characterset: ""
- collation: utf8mb4_polish_ci
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- - name: b
- expressions:
- - b
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_2
- expressions:
- - b
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- - name: b_3
- expressions:
- - b
- - c
- - d
- type: BTREE
- unique: true
- primary: false
- visible: true
- comment: ""
- - name: b_4
- expressions:
- - b
- - d
- type: FULLTEXT
- unique: false
- primary: false
- visible: false
- comment: ""
- - name: idx_a
- expressions:
- - a
- type: BTREE
- unique: false
- primary: false
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t
+ columns:
+ - name: a
+ position: 1
+ default:
+ value: "1"
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: varchar(200)
+ characterset: utf8mb4
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: c
+ position: 3
+ default: null
+ nullable: true
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: This is a comment
+ classification: ""
+ usercomment: ""
+ - name: d
+ position: 4
+ default: null
+ nullable: true
+ type: varchar(10)
+ characterset: ""
+ collation: utf8mb4_polish_ci
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ - name: b
+ expressions:
+ - b
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_2
+ expressions:
+ - b
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_3
+ expressions:
+ - b
+ - c
+ - d
+ type: BTREE
+ unique: true
+ primary: false
+ visible: true
+ comment: ""
+ - name: b_4
+ expressions:
+ - b
+ - d
+ type: FULLTEXT
+ unique: false
+ primary: false
+ visible: false
+ comment: ""
+ - name: idx_a
+ expressions:
+ - a
+ type: BTREE
+ unique: false
+ primary: false
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
@@ -945,58 +971,59 @@
b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE
);
DROP INDEX b on t;
+ ignore_case_sensitive: false
want:
name: test
schemas:
- - name: ""
- tables:
- - name: t
- columns:
- - name: a
- position: 1
- default:
- value: "1"
- nullable: false
- type: int(11)
- characterset: ""
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- - name: b
- position: 2
- default: null
- nullable: false
- type: varchar(200)
- characterset: utf8mb4
- collation: ""
- comment: ""
- classification: ""
- usercomment: ""
- indexes:
- - name: PRIMARY
- expressions:
- - a
- type: BTREE
- unique: true
- primary: true
- visible: true
- comment: ""
- engine: ""
- collation: ""
- rowcount: 0
- datasize: 0
- indexsize: 0
- datafree: 0
- createoptions: ""
- comment: ""
- classification: ""
- usercomment: ""
- foreignkeys: []
- views: []
- functions: []
- streams: []
- tasks: []
+ - name: ""
+ tables:
+ - name: t
+ columns:
+ - name: a
+ position: 1
+ default:
+ value: "1"
+ nullable: false
+ type: int(11)
+ characterset: ""
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ - name: b
+ position: 2
+ default: null
+ nullable: false
+ type: varchar(200)
+ characterset: utf8mb4
+ collation: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ indexes:
+ - name: PRIMARY
+ expressions:
+ - a
+ type: BTREE
+ unique: true
+ primary: true
+ visible: true
+ comment: ""
+ engine: ""
+ collation: ""
+ rowcount: 0
+ datasize: 0
+ indexsize: 0
+ datafree: 0
+ createoptions: ""
+ comment: ""
+ classification: ""
+ usercomment: ""
+ foreignkeys: []
+ views: []
+ functions: []
+ streams: []
+ tasks: []
characterset: ""
collation: ""
extensions: []
diff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.go
index ebebbe3f0c..98b92dc5c6 100644
--- a/backend/plugin/advisor/catalog/walk_through.go
+++ b/backend/plugin/advisor/catalog/walk_through.go
@@ -209,7 +209,8 @@ func (e *WalkThroughError) Error() string {
func (d *DatabaseState) WalkThrough(stmt string) error {
switch d.dbType {
case storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
- return d.mysqlWalkThrough(stmt)
+ err := d.mysqlWalkThrough(stmt)
+ return err
case storepb.Engine_POSTGRES:
if err := d.pgWalkThrough(stmt); err != nil {
if d.ctx.CheckIntegrity {
@@ -252,6 +253,32 @@ func (d *DatabaseState) mysqlWalkThrough(stmt string) error {
return nil
}
+// compareIdentifier returns true if the engine will regard the two identifiers as the same one.
+// TODO(zp): It's used for MySQL, we should refactor the package to make it more clear.
+func compareIdentifier(a, b string, ignoreCaseSensitive bool) bool {
+ if ignoreCaseSensitive {
+ return strings.EqualFold(a, b)
+ }
+ return a == b
+}
+
+// isCurrentDatabase returns true if the given database is the current database of the state.
+func (d *DatabaseState) isCurrentDatabase(database string) bool {
+ return compareIdentifier(d.name, database, d.ctx.IgnoreCaseSensitive)
+}
+
+// isTableExists returns true if the given table exists in the database.
+// TODO(zp): It's used for MySQL, we should refactor the package to make it more clear.
+func (s *SchemaState) getTable(table string) (*TableState, bool) {
+ for k, v := range s.tableSet {
+ if compareIdentifier(k, table, s.ctx.IgnoreCaseSensitive) {
+ return v, true
+ }
+ }
+
+ return nil, false
+}
+
func (d *DatabaseState) changeState(in tidbast.StmtNode) (err *WalkThroughError) {
defer func() {
if err == nil {
@@ -300,24 +327,24 @@ func (d *DatabaseState) renameTable(node *tidbast.RenameTableStmt) *WalkThroughE
oldTableName := tableToTable.OldTable.Name.O
newTableName := tableToTable.NewTable.Name.O
if d.theCurrentDatabase(tableToTable) {
- if oldTableName == newTableName {
+ if compareIdentifier(oldTableName, newTableName, d.ctx.IgnoreCaseSensitive) {
return nil
}
- table, exists := schema.tableSet[oldTableName]
+ table, exists := schema.getTable(oldTableName)
if !exists {
if schema.ctx.CheckIntegrity {
return NewTableNotExistsError(oldTableName)
}
table = schema.createIncompleteTable(oldTableName)
}
- if _, exists := schema.tableSet[newTableName]; exists {
+ if _, exists := schema.getTable(newTableName); exists {
return NewTableExistsError(newTableName)
}
delete(schema.tableSet, table.name)
table.name = newTableName
schema.tableSet[table.name] = table
} else if d.moveToOtherDatabase(tableToTable) {
- _, exists := schema.tableSet[tableToTable.OldTable.Name.O]
+ _, exists := schema.getTable(tableToTable.OldTable.Name.O)
if !exists && schema.ctx.CheckIntegrity {
return NewTableNotExistsError(tableToTable.OldTable.Name.O)
}
@@ -330,31 +357,31 @@ func (d *DatabaseState) renameTable(node *tidbast.RenameTableStmt) *WalkThroughE
}
func (d *DatabaseState) targetDatabase(node *tidbast.TableToTable) string {
- if node.OldTable.Schema.O != "" && node.OldTable.Schema.O != d.name {
+ if node.OldTable.Schema.O != "" && !d.isCurrentDatabase(node.OldTable.Schema.O) {
return node.OldTable.Schema.O
}
return node.NewTable.Schema.O
}
func (d *DatabaseState) moveToOtherDatabase(node *tidbast.TableToTable) bool {
- if node.OldTable.Schema.O != "" && node.OldTable.Schema.O != d.name {
+ if node.OldTable.Schema.O != "" && !d.isCurrentDatabase(node.OldTable.Schema.O) {
return false
}
return node.OldTable.Schema.O != node.NewTable.Schema.O
}
func (d *DatabaseState) theCurrentDatabase(node *tidbast.TableToTable) bool {
- if node.NewTable.Schema.O != "" && node.NewTable.Schema.O != d.name {
+ if node.NewTable.Schema.O != "" && !d.isCurrentDatabase(node.NewTable.Schema.O) {
return false
}
- if node.OldTable.Schema.O != "" && node.OldTable.Schema.O != d.name {
+ if node.OldTable.Schema.O != "" && !d.isCurrentDatabase(node.OldTable.Schema.O) {
return false
}
return true
}
func (d *DatabaseState) dropDatabase(node *tidbast.DropDatabaseStmt) *WalkThroughError {
- if node.Name.O != d.name {
+ if !d.isCurrentDatabase(node.Name.O) {
return NewAccessOtherDatabaseError(d.name, node.Name.O)
}
@@ -363,7 +390,7 @@ func (d *DatabaseState) dropDatabase(node *tidbast.DropDatabaseStmt) *WalkThroug
}
func (d *DatabaseState) alterDatabase(node *tidbast.AlterDatabaseStmt) *WalkThroughError {
- if !node.AlterDefaultDatabase && node.Name.O != d.name {
+ if !node.AlterDefaultDatabase && !d.isCurrentDatabase(node.Name.O) {
return NewAccessOtherDatabaseError(d.name, node.Name.O)
}
@@ -379,7 +406,7 @@ func (d *DatabaseState) alterDatabase(node *tidbast.AlterDatabaseStmt) *WalkThro
}
func (d *DatabaseState) findTableState(tableName *tidbast.TableName, createIncompleteTable bool) (*TableState, *WalkThroughError) {
- if tableName.Schema.O != "" && tableName.Schema.O != d.name {
+ if tableName.Schema.O != "" && !d.isCurrentDatabase(tableName.Schema.O) {
return nil, NewAccessOtherDatabaseError(d.name, tableName.Schema.O)
}
@@ -388,7 +415,7 @@ func (d *DatabaseState) findTableState(tableName *tidbast.TableName, createIncom
schema = d.createSchema("")
}
- table, exists := schema.tableSet[tableName.Name.O]
+ table, exists := schema.getTable(tableName.Name.O)
if !exists {
if schema.ctx.CheckIntegrity {
return nil, NewTableNotExistsError(tableName.Name.O)
@@ -640,7 +667,7 @@ func (s *SchemaState) renameTable(ctx *FinderContext, oldName string, newName st
return nil
}
- table, exists := s.tableSet[oldName]
+ table, exists := s.getTable(oldName)
if !exists {
if ctx.CheckIntegrity {
return &WalkThroughError{
@@ -651,7 +678,7 @@ func (s *SchemaState) renameTable(ctx *FinderContext, oldName string, newName st
table = s.createIncompleteTable(oldName)
}
- if _, exists := s.tableSet[newName]; exists {
+ if _, exists := s.getTable(newName); exists {
return &WalkThroughError{
Type: ErrorTypeTableExists,
Content: fmt.Sprintf("Table `%s` already exists", newName),
@@ -914,7 +941,7 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughError
// TODO(rebelice): deal with DROP VIEW statement.
if !node.IsView {
for _, name := range node.Tables {
- if name.Schema.O != "" && d.name != name.Schema.O {
+ if name.Schema.O != "" && !d.isCurrentDatabase(name.Schema.O) {
return &WalkThroughError{
Type: ErrorTypeAccessOtherDatabase,
Content: fmt.Sprintf("Database `%s` is not the current database `%s`", name.Schema.O, d.name),
@@ -926,7 +953,8 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughError
schema = d.createSchema("")
}
- if _, exists = schema.tableSet[name.Name.O]; !exists {
+ table, exists := schema.getTable(name.Name.O)
+ if !exists {
if node.IfExists || !d.ctx.CheckIntegrity {
return nil
}
@@ -936,7 +964,7 @@ func (d *DatabaseState) dropTable(node *tidbast.DropTableStmt) *WalkThroughError
}
}
- delete(schema.tableSet, name.Name.O)
+ delete(schema.tableSet, table.name)
}
}
return nil
@@ -956,7 +984,7 @@ func (d *DatabaseState) copyTable(node *tidbast.CreateTableStmt) *WalkThroughErr
}
func (d *DatabaseState) createTable(node *tidbast.CreateTableStmt) *WalkThroughError {
- if node.Table.Schema.O != "" && d.name != node.Table.Schema.O {
+ if node.Table.Schema.O != "" && !d.isCurrentDatabase(node.Table.Schema.O) {
return &WalkThroughError{
Type: ErrorTypeAccessOtherDatabase,
Content: fmt.Sprintf("Database `%s` is not the current database `%s`", node.Table.Schema.O, d.name),
@@ -968,7 +996,7 @@ func (d *DatabaseState) createTable(node *tidbast.CreateTableStmt) *WalkThroughE
schema = d.createSchema("")
}
- if _, exists = schema.tableSet[node.Table.Name.O]; exists {
+ if _, exists = schema.getTable(node.Table.Name.O); exists {
if node.IfNotExists {
return nil
}
diff --git a/backend/plugin/advisor/catalog/walk_through_for_pg.go b/backend/plugin/advisor/catalog/walk_through_for_pg.go
index 99913934cf..9440de9a85 100644
--- a/backend/plugin/advisor/catalog/walk_through_for_pg.go
+++ b/backend/plugin/advisor/catalog/walk_through_for_pg.go
@@ -177,7 +177,7 @@ func (d *DatabaseState) pgDropTable(tableDef *ast.TableDef, ifExists bool, _ ast
return err
}
- table, err := schema.getTable(tableDef.Name)
+ table, err := schema.pgGetTable(tableDef.Name)
if err != nil {
if ifExists {
return nil
@@ -283,7 +283,7 @@ func (d *DatabaseState) pgAlterTable(node *ast.AlterTableStmt) *WalkThroughError
if err != nil {
return err
}
- table, err := schema.getTable(node.Table.Name)
+ table, err := schema.pgGetTable(node.Table.Name)
if err != nil {
return err
}
@@ -1027,7 +1027,7 @@ func (d *DatabaseState) getSchema(schemaName string) (*SchemaState, *WalkThrough
return schema, nil
}
-func (s *SchemaState) getTable(tableName string) (*TableState, *WalkThroughError) {
+func (s *SchemaState) pgGetTable(tableName string) (*TableState, *WalkThroughError) {
table, exists := s.tableSet[tableName]
if !exists {
return nil, &WalkThroughError{
diff --git a/backend/plugin/advisor/catalog/walk_through_test.go b/backend/plugin/advisor/catalog/walk_through_test.go
index 26a843c829..381c076aa9 100644
--- a/backend/plugin/advisor/catalog/walk_through_test.go
+++ b/backend/plugin/advisor/catalog/walk_through_test.go
@@ -19,8 +19,10 @@ import (
type testData struct {
Statement string
- Want *storepb.DatabaseSchemaMetadata
- Err *WalkThroughError
+ // Use custom yaml tag to avoid generate field name `ignorecasesensitive`.
+ IgnoreCaseSensitive bool `yaml:"ignore_case_sensitive"`
+ Want *storepb.DatabaseSchemaMetadata
+ Err *WalkThroughError
}
func TestMySQLWalkThrough(t *testing.T) {
@@ -124,9 +126,9 @@ func runWalkThroughTest(t *testing.T, file string, engineType storepb.Engine, or
for i, test := range tests {
var state *DatabaseState
if originDatabase != nil {
- state = newDatabaseState(originDatabase, &FinderContext{CheckIntegrity: true, EngineType: engineType})
+ state = newDatabaseState(originDatabase, &FinderContext{CheckIntegrity: true, EngineType: engineType, IgnoreCaseSensitive: test.IgnoreCaseSensitive})
} else {
- finder := NewEmptyFinder(&FinderContext{CheckIntegrity: false, EngineType: engineType})
+ finder := NewEmptyFinder(&FinderContext{CheckIntegrity: false, EngineType: engineType, IgnoreCaseSensitive: test.IgnoreCaseSensitive})
state = finder.Origin
}
diff --git a/backend/runner/plancheck/statement_advise_executor.go b/backend/runner/plancheck/statement_advise_executor.go
index 14ed1acb89..4fca4c5a90 100644
--- a/backend/runner/plancheck/statement_advise_executor.go
+++ b/backend/runner/plancheck/statement_advise_executor.go
@@ -145,7 +145,7 @@ func (e *StatementAdviseExecutor) runForDatabaseTarget(ctx context.Context, conf
}
}
- catalog, err := e.store.NewCatalog(ctx, database.UID, instance.Engine, getSyntaxMode(changeType))
+ catalog, err := e.store.NewCatalog(ctx, database.UID, instance.Engine, store.IgnoreDatabaseAndTableCaseSensitive(instance), getSyntaxMode(changeType))
if err != nil {
return nil, common.Wrapf(err, common.Internal, "failed to create a catalog")
}
@@ -356,7 +356,7 @@ func (e *StatementAdviseExecutor) runForDatabaseGroupTarget(ctx context.Context,
}
}
- catalog, err := e.store.NewCatalog(ctx, db.UID, instance.Engine, getSyntaxMode(changeType))
+ catalog, err := e.store.NewCatalog(ctx, db.UID, instance.Engine, store.IgnoreDatabaseAndTableCaseSensitive(instance), getSyntaxMode(changeType))
if err != nil {
return nil, common.Wrapf(err, common.Internal, "failed to create a catalog")
}
diff --git a/backend/sql-server/advise.go b/backend/sql-server/advise.go
index 1b75c395bc..1bac2513df 100644
--- a/backend/sql-server/advise.go
+++ b/backend/sql-server/advise.go
@@ -29,7 +29,7 @@ type catalogService struct {
func newCatalogService(dbType storepb.Engine) *catalogService {
return &catalogService{
- finder: catalog.NewEmptyFinder(&catalog.FinderContext{CheckIntegrity: false, EngineType: dbType}),
+ finder: catalog.NewEmptyFinder(&catalog.FinderContext{CheckIntegrity: false, EngineType: dbType, IgnoreCaseSensitive: false}),
}
}
diff --git a/backend/store/catalog.go b/backend/store/catalog.go
index 0e226f2e09..230f4fda23 100644
--- a/backend/store/catalog.go
+++ b/backend/store/catalog.go
@@ -18,7 +18,7 @@ type Catalog struct {
}
// NewCatalog creates a new database catalog.
-func (s *Store) NewCatalog(ctx context.Context, databaseID int, engineType storepb.Engine, syntaxMode advisor.SyntaxMode) (catalog.Catalog, error) {
+func (s *Store) NewCatalog(ctx context.Context, databaseID int, engineType storepb.Engine, ignoreCaseSensitive bool, syntaxMode advisor.SyntaxMode) (catalog.Catalog, error) {
c := &Catalog{}
if syntaxMode == advisor.SyntaxModeSDL {
@@ -33,7 +33,7 @@ func (s *Store) NewCatalog(ctx context.Context, databaseID int, engineType store
return nil, nil
}
- c.Finder = catalog.NewFinder(databaseMeta.Metadata, &catalog.FinderContext{CheckIntegrity: true, EngineType: engineType})
+ c.Finder = catalog.NewFinder(databaseMeta.Metadata, &catalog.FinderContext{CheckIntegrity: true, EngineType: engineType, IgnoreCaseSensitive: ignoreCaseSensitive})
return c, nil
}
@@ -45,6 +45,6 @@ func (c *Catalog) GetFinder() *catalog.Finder {
// NewEmptyCatalog creates a new empty database catalog.
func NewEmptyCatalog(engineType storepb.Engine) (catalog.Catalog, error) {
return &Catalog{
- catalog.NewEmptyFinder(&catalog.FinderContext{CheckIntegrity: false, EngineType: engineType}),
+ catalog.NewEmptyFinder(&catalog.FinderContext{CheckIntegrity: false, EngineType: engineType, IgnoreCaseSensitive: false}),
}, nil
}