Skip to content

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

fix: handle nil pointer engine_mysql_use_innodb (#9319)

zll600196c41e390ff
diff --git a/backend/plugin/advisor/mysqlwip/advisor_use_innodb.go b/backend/plugin/advisor/mysqlwip/advisor_use_innodb.go
index 75bb346e6e..db9605ab10 100644
--- a/backend/plugin/advisor/mysqlwip/advisor_use_innodb.go
+++ b/backend/plugin/advisor/mysqlwip/advisor_use_innodb.go
@@ -79,6 +79,9 @@ func (c *useInnoDBChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
}
for _, tableOption := range ctx.CreateTableOptions().AllCreateTableOption() {
if tableOption.ENGINE_SYMBOL() != nil && tableOption.EngineRef() != nil {
+ if tableOption.EngineRef().TextOrIdentifier() == nil {
+ continue
+ }
engine := mysqlparser.NormalizeMySQLTextOrIdentifier(tableOption.EngineRef().TextOrIdentifier())
if strings.ToLower(engine) != innoDB {
content := "CREATE " + ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)
@@ -91,11 +94,20 @@ func (c *useInnoDBChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
}
func (c *useInnoDBChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if ctx.AlterTableActions() == nil || ctx.AlterTableActions().AlterCommandList() == nil {
+ return
+ }
+ if ctx.AlterTableActions().AlterCommandList().AlterList() == nil {
+ return
+ }
code := advisor.Ok
for _, option := range ctx.AlterTableActions().AlterCommandList().AlterList().AllCreateTableOptionsSpaceSeparated() {
for _, op := range option.AllCreateTableOption() {
switch {
case op.ENGINE_SYMBOL() != nil:
+ if op.EngineRef() == nil {
+ continue
+ }
engine := op.EngineRef().GetText()
if strings.ToLower(engine) != innoDB {
code = advisor.NotInnoDBEngine
diff --git a/backend/plugin/advisor/mysqlwip/test/engine_mysql_use_innodb.yaml b/backend/plugin/advisor/mysqlwip/test/engine_mysql_use_innodb.yaml
index 766f61f759..d7cec5864d 100644
--- a/backend/plugin/advisor/mysqlwip/test/engine_mysql_use_innodb.yaml
+++ b/backend/plugin/advisor/mysqlwip/test/engine_mysql_use_innodb.yaml
@@ -1,3 +1,54 @@
+- statement: |
+ CREATE TABLE userTable(
+ id INT NOT NULL,
+ name VARCHAR(255) CHARSET ascii,
+ roomId INT,
+ time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',
+ time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',
+ content BLOB NOT NULL COMMENT 'comment',
+ json_content JSON NOT NULL COMMENT 'comment',
+ INDEX idx1(name),
+ UNIQUE KEY uk1(id, name),
+ FOREIGN KEY fk1(roomId) REFERENCES room(id),
+ INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;
+ want:
+ - status: WARN
+ code: 501
+ title: engine.mysql.use-innodb
+ content: |-
+ "CREATE TABLE userTable(
+ id INT NOT NULL,
+ name VARCHAR(255) CHARSET ascii,
+ roomId INT,
+ time_created TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',
+ time_updated TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',
+ content BLOB NOT NULL COMMENT 'comment',
+ json_content JSON NOT NULL COMMENT 'comment',
+ INDEX idx1(name),
+ UNIQUE KEY uk1(id, name),
+ FOREIGN KEY fk1(roomId) REFERENCES room(id),
+ INDEX idx_userTable_content(content)) ENGINE = CSV COLLATE latin1_bin;" doesn't use InnoDB engine
+ line: 12
+ details: ""
+- statement: |
+ CREATE TABLE user(
+ id INT PRIMARY KEY COMMENT 'comment',
+ name VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'comment',
+ room_id INT NOT NULL DEFAULT 0 COMMENT 'comment',
+ creator_id INT NOT NULL DEFAULT 0 COMMENT 'comment',
+ created_ts TIMESTAMP NOT NULL DEFAULT NOW() COMMENT 'comment',
+ updater_id INT NOT NULL DEFAULT 0 COMMENT 'comment',
+ updated_ts TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() COMMENT 'comment',
+ INDEX idx_user_name(name),
+ UNIQUE KEY uk_user_id_name(id, name)
+ ) ENGINE = INNODB COMMENT 'comment';
+ want:
+ - status: SUCCESS
+ code: 0
+ title: OK
+ content: ""
+ line: 0
+ details: ""
- statement: CREATE TABLE book(id int) ENGINE = INNODB;
want:
- status: SUCCESS