Skip to content

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

fix: introduce IsTopMySQLRule for walk-through and mysql advisor (#11150)

rebelicea127d5589b0f
diff --git a/backend/plugin/advisor/catalog/walk_through_for_mysql.go b/backend/plugin/advisor/catalog/walk_through_for_mysql.go
index 8cbaf42865..cae0b2c27c 100644
--- a/backend/plugin/advisor/catalog/walk_through_for_mysql.go
+++ b/backend/plugin/advisor/catalog/walk_through_for_mysql.go
@@ -81,6 +81,9 @@ func (d *DatabaseState) mysqlChangeState(in *mysqlparser.ParseResult) (err *Walk
// EnterCreateTable is called when production createTable is entered.
func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -172,6 +175,9 @@ func (l *mysqlListener) EnterCreateTable(ctx *mysql.CreateTableContext) {
// EnterDropTable is called when production dropTable is entered.
func (l *mysqlListener) EnterDropTable(ctx *mysql.DropTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRefList() == nil {
return
}
@@ -208,6 +214,9 @@ func (l *mysqlListener) EnterDropTable(ctx *mysql.DropTableContext) {
// EnterAlterTable is called when production alterTable is entered.
func (l *mysqlListener) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
// todo: maybe need to do error handle.
return
@@ -377,6 +386,9 @@ func (l *mysqlListener) EnterAlterTable(ctx *mysql.AlterTableContext) {
// EnterDropIndex is called when production dropIndex is entered.
func (l *mysqlListener) EnterDropIndex(ctx *mysql.DropIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
@@ -398,6 +410,9 @@ func (l *mysqlListener) EnterDropIndex(ctx *mysql.DropIndexContext) {
}
func (l *mysqlListener) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateIndexTarget() == nil || ctx.CreateIndexTarget().TableRef() == nil {
return
}
@@ -452,6 +467,9 @@ func (l *mysqlListener) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
// EnterAlterDatabase is called when production alterDatabase is entered.
func (l *mysqlListener) EnterAlterDatabase(ctx *mysql.AlterDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.SchemaRef() != nil {
databaseName := mysqlparser.NormalizeMySQLSchemaRef(ctx.SchemaRef())
if !l.databaseState.isCurrentDatabase(databaseName) {
@@ -478,6 +496,9 @@ func (l *mysqlListener) EnterAlterDatabase(ctx *mysql.AlterDatabaseContext) {
// EnterDropDatabase is called when production dropDatabase is entered.
func (l *mysqlListener) EnterDropDatabase(ctx *mysql.DropDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.SchemaRef() == nil {
return
}
@@ -493,6 +514,9 @@ func (l *mysqlListener) EnterDropDatabase(ctx *mysql.DropDatabaseContext) {
// EnterCreateDatabase is called when production createDatabase is entered.
func (l *mysqlListener) EnterCreateDatabase(ctx *mysql.CreateDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.SchemaName() == nil {
return
}
@@ -502,6 +526,9 @@ func (l *mysqlListener) EnterCreateDatabase(ctx *mysql.CreateDatabaseContext) {
// EnterRenameTableStatement is called when production renameTableStatement is entered.
func (l *mysqlListener) EnterRenameTableStatement(ctx *mysql.RenameTableStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, pair := range ctx.AllRenamePair() {
schema, exists := l.databaseState.schemaSet[""]
if !exists {
@@ -545,6 +572,9 @@ func (l *mysqlListener) EnterRenameTableStatement(ctx *mysql.RenameTableStatemen
}
func (l *mysqlListener) EnterCreateTrigger(ctx *mysql.CreateTriggerContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TriggerName() == nil {
return
}
@@ -562,6 +592,9 @@ func (l *mysqlListener) EnterCreateTrigger(ctx *mysql.CreateTriggerContext) {
}
func (*mysqlListener) EnterCreateProcedure(ctx *mysql.CreateProcedureContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.ProcedureName() == nil {
return
}
@@ -569,6 +602,9 @@ func (*mysqlListener) EnterCreateProcedure(ctx *mysql.CreateProcedureContext) {
}
func (*mysqlListener) EnterCreateEvent(ctx *mysql.CreateEventContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.EventName() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go b/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
index 9073b8c405..9b3ace25d6 100644
--- a/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_charset_allowlist.go
@@ -83,6 +83,9 @@ func (checker *charsetAllowlistChecker) EnterQuery(ctx *mysql.QueryContext) {
// EnterCreateDatabase is called when production createDatabase is entered.
func (checker *charsetAllowlistChecker) EnterCreateDatabase(ctx *mysql.CreateDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, option := range ctx.AllCreateDatabaseOption() {
if option.DefaultCharset() != nil {
charset := mysqlparser.NormalizeMySQLCharsetName(option.DefaultCharset().CharsetName())
@@ -107,6 +110,9 @@ func (checker *charsetAllowlistChecker) checkCharset(charset string, lineNumber
// EnterCreateTable is called when production createTable is entered.
func (checker *charsetAllowlistChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateTableOptions() != nil {
for _, option := range ctx.CreateTableOptions().AllCreateTableOption() {
if option.DefaultCharset() != nil {
@@ -142,6 +148,9 @@ func (checker *charsetAllowlistChecker) EnterCreateTable(ctx *mysql.CreateTableC
// EnterAlterDatabase is called when production alterDatabase is entered.
func (checker *charsetAllowlistChecker) EnterAlterDatabase(ctx *mysql.AlterDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, option := range ctx.AllAlterDatabaseOption() {
if option.CreateDatabaseOption() == nil || option.CreateDatabaseOption().DefaultCharset() == nil {
continue
@@ -154,6 +163,9 @@ func (checker *charsetAllowlistChecker) EnterAlterDatabase(ctx *mysql.AlterDatab
// EnterAlterTable is called when production alterTable is entered.
func (checker *charsetAllowlistChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil || ctx.AlterTableActions().AlterCommandList() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go b/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
index 7b6146f174..691d9d1b38 100644
--- a/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_collation_allowlist.go
@@ -84,6 +84,9 @@ func (checker *collationAllowlistChecker) EnterQuery(ctx *mysql.QueryContext) {
// EnterCreateDatabase is called when production createDatabase is entered.
func (checker *collationAllowlistChecker) EnterCreateDatabase(ctx *mysql.CreateDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, option := range ctx.AllCreateDatabaseOption() {
if option != nil && option.DefaultCollation() != nil && option.DefaultCollation().CollationName() != nil {
collation := mysqlparser.NormalizeMySQLCollationName(option.DefaultCollation().CollationName())
@@ -107,6 +110,9 @@ func (checker *collationAllowlistChecker) checkCollation(collation string, lineN
// EnterCreateTable is called when production createTable is entered.
func (checker *collationAllowlistChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateTableOptions() != nil {
for _, option := range ctx.CreateTableOptions().AllCreateTableOption() {
if option != nil && option.DefaultCollation() != nil && option.DefaultCollation().CollationName() != nil {
@@ -140,6 +146,9 @@ func (checker *collationAllowlistChecker) EnterCreateTable(ctx *mysql.CreateTabl
// EnterAlterDatabase is called when production alterDatabase is entered.
func (checker *collationAllowlistChecker) EnterAlterDatabase(ctx *mysql.AlterDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, option := range ctx.AllAlterDatabaseOption() {
if option == nil || option.CreateDatabaseOption() == nil || option.CreateDatabaseOption().DefaultCollation() == nil || option.CreateDatabaseOption().DefaultCollation().CollationName() == nil {
continue
@@ -151,6 +160,9 @@ func (checker *collationAllowlistChecker) EnterAlterDatabase(ctx *mysql.AlterDat
// EnterAlterTable is called when production alterTable is entered.
func (checker *collationAllowlistChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_colum_require_default.go b/backend/plugin/advisor/mysql/advisor_colum_require_default.go
index ae2f77c7f9..631fb286ae 100644
--- a/backend/plugin/advisor/mysql/advisor_colum_require_default.go
+++ b/backend/plugin/advisor/mysql/advisor_colum_require_default.go
@@ -68,6 +68,9 @@ type columnRequireDefaultChecker struct {
}
func (checker *columnRequireDefaultChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -93,6 +96,9 @@ func (checker *columnRequireDefaultChecker) EnterCreateTable(ctx *mysql.CreateTa
}
func (checker *columnRequireDefaultChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
index b1afbcd81f..339eb3b455 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_initial_value.go
@@ -78,6 +78,9 @@ type columnAutoIncrementInitialValueChecker struct {
}
func (checker *columnAutoIncrementInitialValueChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateTableOptions() == nil || ctx.TableName() == nil {
return
}
@@ -108,6 +111,9 @@ func (checker *columnAutoIncrementInitialValueChecker) EnterCreateTable(ctx *mys
// EnterAlterTable is called when production alterTable is entered.
func (checker *columnAutoIncrementInitialValueChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
index 6b528ea3cc..cd3fb5c028 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_integer.go
@@ -71,6 +71,9 @@ type columnAutoIncrementMustIntegerChecker struct {
}
func (checker *columnAutoIncrementMustIntegerChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -86,6 +89,9 @@ func (checker *columnAutoIncrementMustIntegerChecker) EnterCreateTable(ctx *mysq
}
func (checker *columnAutoIncrementMustIntegerChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
index e7f22c1477..42a7d7d6f9 100644
--- a/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
+++ b/backend/plugin/advisor/mysql/advisor_column_auto_increment_must_unsigned.go
@@ -71,6 +71,9 @@ type columnAutoIncrementMustUnsignedChecker struct {
}
func (checker *columnAutoIncrementMustUnsignedChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -86,6 +89,9 @@ func (checker *columnAutoIncrementMustUnsignedChecker) EnterCreateTable(ctx *mys
}
func (checker *columnAutoIncrementMustUnsignedChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go b/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
index d7e300bdb7..16748c2e96 100644
--- a/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_column_comment_convention.go
@@ -79,6 +79,9 @@ type columnCommentConventionChecker struct {
}
func (checker *columnCommentConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -104,6 +107,9 @@ func (checker *columnCommentConventionChecker) EnterCreateTable(ctx *mysql.Creat
}
func (checker *columnCommentConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
index fc6892c681..dbf5b0ec08 100644
--- a/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_column_current_time_count_limit.go
@@ -71,6 +71,9 @@ type columnCurrentTimeCountLimitChecker struct {
}
func (checker *columnCurrentTimeCountLimitChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -86,6 +89,9 @@ func (checker *columnCurrentTimeCountLimitChecker) EnterCreateTable(ctx *mysql.C
}
func (checker *columnCurrentTimeCountLimitChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
index 68263a44e7..99ee9d586b 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing.go
@@ -76,6 +76,9 @@ func (checker *columnDisallowChangingChecker) EnterQuery(ctx *mysql.QueryContext
}
func (checker *columnDisallowChangingChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
index 371ef9e36c..e1a4e29801 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_order.go
@@ -76,6 +76,9 @@ func (checker *columnDisallowChangingOrderChecker) EnterQuery(ctx *mysql.QueryCo
}
func (checker *columnDisallowChangingOrderChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
index e899f16c73..90935ad237 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_changing_type.go
@@ -81,6 +81,9 @@ func (checker *columnDisallowChangingTypeChecker) EnterQuery(ctx *mysql.QueryCon
// EnterAlterTable is called when production alterTable is entered.
func (checker *columnDisallowChangingTypeChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go b/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
index 5705e86f95..ab1a369d48 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_drop_in_index.go
@@ -78,6 +78,9 @@ type columnDisallowDropInIndexChecker struct {
}
func (checker *columnDisallowDropInIndexChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -114,6 +117,9 @@ func (checker *columnDisallowDropInIndexChecker) EnterCreateTable(ctx *mysql.Cre
}
func (checker *columnDisallowDropInIndexChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
index bd74bfe990..6aa20496c9 100644
--- a/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_column_disallow_set_charset.go
@@ -76,6 +76,9 @@ func (checker *columnDisallowSetCharsetChecker) EnterQuery(ctx *mysql.QueryConte
}
func (checker *columnDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -104,6 +107,9 @@ func (checker *columnDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.Crea
}
func (checker *columnDisallowSetCharsetChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
index bb67c59a65..011e8efb77 100644
--- a/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
+++ b/backend/plugin/advisor/mysql/advisor_column_maximum_character_length.go
@@ -76,6 +76,9 @@ type columnMaximumCharacterLengthChecker struct {
}
func (checker *columnMaximumCharacterLengthChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -109,6 +112,9 @@ func (checker *columnMaximumCharacterLengthChecker) EnterCreateTable(ctx *mysql.
}
func (checker *columnMaximumCharacterLengthChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go b/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
index 8c79ae9a73..80201eab34 100644
--- a/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
+++ b/backend/plugin/advisor/mysql/advisor_column_maximum_varchar_length.go
@@ -76,6 +76,9 @@ type columnMaximumVarcharLengthChecker struct {
}
func (checker *columnMaximumVarcharLengthChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -109,6 +112,9 @@ func (checker *columnMaximumVarcharLengthChecker) EnterCreateTable(ctx *mysql.Cr
}
func (checker *columnMaximumVarcharLengthChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_no_null.go b/backend/plugin/advisor/mysql/advisor_column_no_null.go
index c8275bbc76..d5f18306b9 100644
--- a/backend/plugin/advisor/mysql/advisor_column_no_null.go
+++ b/backend/plugin/advisor/mysql/advisor_column_no_null.go
@@ -115,6 +115,9 @@ func (checker *columnNoNullChecker) generateAdvice() []advisor.Advice {
}
func (checker *columnNoNullChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -147,6 +150,9 @@ func (checker *columnNoNullChecker) EnterCreateTable(ctx *mysql.CreateTableConte
}
func (checker *columnNoNullChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_required.go b/backend/plugin/advisor/mysql/advisor_column_required.go
index 8636e93144..5e58321e78 100644
--- a/backend/plugin/advisor/mysql/advisor_column_required.go
+++ b/backend/plugin/advisor/mysql/advisor_column_required.go
@@ -79,11 +79,17 @@ type columnRequirementChecker struct {
// EnterCreateDatabase is called when production createDatabase is entered.
func (checker *columnRequirementChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.createTable(ctx)
}
// EnterDropTable is called when production dropTable is entered.
func (checker *columnRequirementChecker) EnterDropTable(ctx *mysql.DropTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRefList() == nil {
return
}
@@ -96,6 +102,9 @@ func (checker *columnRequirementChecker) EnterDropTable(ctx *mysql.DropTableCont
// EnterAlterTable is called when production alterTable is entered.
func (checker *columnRequirementChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
index 9d0d8cc007..b61a78e39e 100644
--- a/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
+++ b/backend/plugin/advisor/mysql/advisor_column_set_default_for_not_null.go
@@ -71,6 +71,9 @@ type columnSetDefaultForNotNullChecker struct {
}
func (checker *columnSetDefaultForNotNullChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -192,6 +195,9 @@ func (*columnSetDefaultForNotNullChecker) needDefault(ctx mysql.IFieldDefinition
}
func (checker *columnSetDefaultForNotNullChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go b/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
index 1b34d72316..20428268ec 100644
--- a/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
+++ b/backend/plugin/advisor/mysql/advisor_column_type_disallow_list.go
@@ -81,6 +81,9 @@ type columnTypeDisallowListChecker struct {
}
func (checker *columnTypeDisallowListChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -124,6 +127,9 @@ func (checker *columnTypeDisallowListChecker) checkFieldDefinition(tableName, co
// EnterAlterTable is called when production alterTable is entered.
func (checker *columnTypeDisallowListChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
index 92f3bf0c43..980c132fa4 100644
--- a/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
+++ b/backend/plugin/advisor/mysql/advisor_database_drop_empty_db.go
@@ -73,6 +73,9 @@ type allowDropEmptyDBChecker struct {
// EnterDropDatabase is called when production dropDatabase is entered.
func (checker *allowDropEmptyDBChecker) EnterDropDatabase(ctx *mysql.DropDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.SchemaRef() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_disallow_procedure.go b/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
index c6fbf259a7..183f57b127 100644
--- a/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
+++ b/backend/plugin/advisor/mysql/advisor_disallow_procedure.go
@@ -73,6 +73,9 @@ func (checker *procedureDisallowCreateChecker) EnterQuery(ctx *mysql.QueryContex
// EnterCreateProcedure is to check if creating procedure is forbidden.
func (checker *procedureDisallowCreateChecker) EnterCreateProcedure(ctx *mysql.CreateProcedureContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.ProcedureName() != nil {
code = advisor.DisallowCreateProcedure
diff --git a/backend/plugin/advisor/mysql/advisor_event_disallow_create.go b/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
index 1dc1e0e534..6f0c5f4e9c 100644
--- a/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_event_disallow_create.go
@@ -72,6 +72,9 @@ func (checker *eventDisallowCreateChecker) EnterQuery(ctx *mysql.QueryContext) {
}
func (checker *eventDisallowCreateChecker) EnterCreateEvent(ctx *mysql.CreateEventContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.EventName() != nil {
code = advisor.DisallowCreateEvent
diff --git a/backend/plugin/advisor/mysql/advisor_function_disallow_create.go b/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
index 3da8dd4116..f014732c92 100644
--- a/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_function_disallow_create.go
@@ -72,6 +72,9 @@ func (checker *functionDisallowCreateChecker) EnterQuery(ctx *mysql.QueryContext
}
func (checker *functionDisallowCreateChecker) EnterCreateFunction(ctx *mysql.CreateFunctionContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.FunctionName() != nil {
code = advisor.DisallowCreateFunction
diff --git a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
index 397e074efe..5632b6b961 100644
--- a/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_index_key_number_limit.go
@@ -77,6 +77,9 @@ type indexKeyNumberLimitChecker struct {
}
func (checker *indexKeyNumberLimitChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -133,6 +136,9 @@ func (checker *indexKeyNumberLimitChecker) handleConstraintDef(tableName string,
}
func (checker *indexKeyNumberLimitChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
switch ctx.GetType_().GetTokenType() {
case mysql.MySQLParserFULLTEXT_SYMBOL, mysql.MySQLParserSPATIAL_SYMBOL:
return
@@ -163,6 +169,9 @@ func (checker *indexKeyNumberLimitChecker) EnterCreateIndex(ctx *mysql.CreateInd
}
func (checker *indexKeyNumberLimitChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
index 82cdcc3dcb..98d72290e4 100644
--- a/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
+++ b/backend/plugin/advisor/mysql/advisor_index_no_duplicate_column.go
@@ -71,6 +71,9 @@ type indexNoDuplicateColumnChecker struct {
}
func (checker *indexNoDuplicateColumnChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -91,6 +94,9 @@ func (checker *indexNoDuplicateColumnChecker) EnterCreateTable(ctx *mysql.Create
}
func (checker *indexNoDuplicateColumnChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
@@ -121,6 +127,9 @@ func (checker *indexNoDuplicateColumnChecker) EnterAlterTable(ctx *mysql.AlterTa
}
func (checker *indexNoDuplicateColumnChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
switch ctx.GetType_().GetTokenType() {
case mysql.MySQLParserFULLTEXT_SYMBOL, mysql.MySQLParserSPATIAL_SYMBOL:
return
diff --git a/backend/plugin/advisor/mysql/advisor_index_pk_type.go b/backend/plugin/advisor/mysql/advisor_index_pk_type.go
index 375682b87b..2dabcfea59 100644
--- a/backend/plugin/advisor/mysql/advisor_index_pk_type.go
+++ b/backend/plugin/advisor/mysql/advisor_index_pk_type.go
@@ -79,6 +79,9 @@ type indexPkTypeChecker struct {
}
func (checker *indexPkTypeChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -105,6 +108,9 @@ func (checker *indexPkTypeChecker) EnterCreateTable(ctx *mysql.CreateTableContex
}
func (checker *indexPkTypeChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
index d436eb45a1..22c58bf456 100644
--- a/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
+++ b/backend/plugin/advisor/mysql/advisor_index_primary_key_type_allowlist.go
@@ -86,6 +86,9 @@ type indexPrimaryKeyTypeAllowlistChecker struct {
}
func (checker *indexPrimaryKeyTypeAllowlistChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -112,6 +115,9 @@ func (checker *indexPrimaryKeyTypeAllowlistChecker) EnterCreateTable(ctx *mysql.
}
func (checker *indexPrimaryKeyTypeAllowlistChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
index 9f2a1153e3..cd61b19f91 100644
--- a/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_index_total_number_limit.go
@@ -117,6 +117,9 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []advisor.Advice {
// EnterCreateTable is called when production createTable is entered.
func (checker *indexTotalNumberLimitChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -126,6 +129,9 @@ func (checker *indexTotalNumberLimitChecker) EnterCreateTable(ctx *mysql.CreateT
}
func (checker *indexTotalNumberLimitChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateIndexTarget() == nil || ctx.CreateIndexTarget().TableRef() == nil {
return
}
@@ -135,6 +141,9 @@ func (checker *indexTotalNumberLimitChecker) EnterCreateIndex(ctx *mysql.CreateI
// EnterAlterTable is called when production alterTable is entered.
func (checker *indexTotalNumberLimitChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go b/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
index 28b5d0836a..58897de229 100644
--- a/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
+++ b/backend/plugin/advisor/mysql/advisor_index_type_allow_list.go
@@ -76,6 +76,9 @@ type indexTypeAllowListChecker struct {
}
func (checker *indexTypeAllowListChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -92,6 +95,9 @@ func (checker *indexTypeAllowListChecker) EnterCreateTable(ctx *mysql.CreateTabl
}
func (checker *indexTypeAllowListChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
@@ -130,6 +136,9 @@ func (checker *indexTypeAllowListChecker) handleConstraintDef(ctx mysql.ITableCo
}
func (checker *indexTypeAllowListChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateIndexTarget() == nil || ctx.CreateIndexTarget().TableRef() == nil || ctx.CreateIndexTarget().KeyListVariants() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
index 9f2d123d0f..7d08a88505 100644
--- a/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
+++ b/backend/plugin/advisor/mysql/advisor_index_type_no_blob.go
@@ -77,6 +77,9 @@ type indexTypeNoBlobChecker struct {
}
func (checker *indexTypeNoBlobChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -103,6 +106,9 @@ func (checker *indexTypeNoBlobChecker) EnterCreateTable(ctx *mysql.CreateTableCo
}
func (checker *indexTypeNoBlobChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
@@ -157,6 +163,9 @@ func (checker *indexTypeNoBlobChecker) EnterAlterTable(ctx *mysql.AlterTableCont
}
func (checker *indexTypeNoBlobChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.GetType_() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
index 01df24b462..ea7fb79335 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand.go
@@ -81,6 +81,9 @@ func (checker *insertDisallowOrderByRandChecker) EnterQuery(ctx *mysql.QueryCont
// EnterInsertStatement is called when production insertStatement is entered.
func (checker *insertDisallowOrderByRandChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.InsertQueryExpression() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
index 150c965be3..3cc8a88fa4 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_must_specify_column.go
@@ -78,6 +78,9 @@ func (checker *insertMustSpecifyColumnChecker) EnterQuery(ctx *mysql.QueryContex
// EnterInsertStatement is called when production insertStatement is entered.
func (checker *insertMustSpecifyColumnChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.InsertQueryExpression() != nil {
checker.hasSelect = true
}
diff --git a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
index bd403f59d6..c9b93f6333 100644
--- a/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_insert_row_limit.go
@@ -93,6 +93,9 @@ func (checker *insertRowLimitChecker) EnterQuery(ctx *mysql.QueryContext) {
// EnterInsertStatement is called when production insertStatement is entered.
func (checker *insertRowLimitChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.line = checker.baseLine + ctx.GetStart().GetLine()
if ctx.InsertQueryExpression() != nil {
checker.handleInsertQueryExpression(ctx.InsertQueryExpression())
diff --git a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go b/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
index 9550d8c3f1..83776ebec7 100644
--- a/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/mysql/advisor_migration_compatibility.go
@@ -91,6 +91,9 @@ func (checker *compatibilityChecker) ExitQuery(ctx *mysql.QueryContext) {
// EnterCreateTable is called when production createTable is entered.
func (checker *compatibilityChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -103,21 +106,33 @@ func (checker *compatibilityChecker) EnterCreateTable(ctx *mysql.CreateTableCont
}
// EnterDropDatabase is called when production dropDatabase is entered.
-func (checker *compatibilityChecker) EnterDropDatabase(_ *mysql.DropDatabaseContext) {
+func (checker *compatibilityChecker) EnterDropDatabase(ctx *mysql.DropDatabaseContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.code = advisor.CompatibilityDropDatabase
}
// EnterRenameTableStatement is called when production renameTableStatement is entered.
-func (checker *compatibilityChecker) EnterRenameTableStatement(_ *mysql.RenameTableStatementContext) {
+func (checker *compatibilityChecker) EnterRenameTableStatement(ctx *mysql.RenameTableStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.code = advisor.CompatibilityRenameTable
}
// EnterDropTable is called when production dropTable is entered.
-func (checker *compatibilityChecker) EnterDropTable(_ *mysql.DropTableContext) {
+func (checker *compatibilityChecker) EnterDropTable(ctx *mysql.DropTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.code = advisor.CompatibilityDropTable
}
func (checker *compatibilityChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil || ctx.AlterTableActions().AlterCommandList() == nil {
return
}
@@ -212,6 +227,9 @@ func (checker *compatibilityChecker) EnterAlterTable(ctx *mysql.AlterTableContex
// EnterCreateIndex is called when production createIndex is entered.
func (checker *compatibilityChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.GetType_() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
index 4eda987db2..c102151371 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_auto_increment_column.go
@@ -80,6 +80,9 @@ type namingAutoIncrementColumnChecker struct {
}
func (checker *namingAutoIncrementColumnChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil || ctx.TableElementList() == nil {
return
}
@@ -112,6 +115,9 @@ func (*namingAutoIncrementColumnChecker) isAutoIncrement(ctx mysql.IFieldDefinit
// EnterAlterTable is called when production alterTable is entered.
func (checker *namingAutoIncrementColumnChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_column.go b/backend/plugin/advisor/mysql/advisor_naming_column.go
index e182af2f15..1bb940b64c 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_column.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_column.go
@@ -79,6 +79,9 @@ type namingColumnConventionChecker struct {
// EnterCreateTable is called when production createTable is entered.
func (checker *namingColumnConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -105,6 +108,9 @@ func (checker *namingColumnConventionChecker) EnterCreateTable(ctx *mysql.Create
// EnterAlterTable is called when production alterTable is entered.
func (checker *namingColumnConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
index 36f878d043..68821b8d8c 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_foreign_key_convention.go
@@ -86,6 +86,9 @@ func (checker *namingFKConventionChecker) EnterQuery(ctx *mysql.QueryContext) {
}
func (checker *namingFKConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -111,6 +114,9 @@ func (checker *namingFKConventionChecker) EnterCreateTable(ctx *mysql.CreateTabl
}
func (checker *namingFKConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go b/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
index 29cb35996c..049c9d7436 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_index_convention.go
@@ -96,6 +96,9 @@ func (checker *namingIndexConventionChecker) EnterQuery(ctx *mysql.QueryContext)
}
func (checker *namingIndexConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -121,6 +124,9 @@ func (checker *namingIndexConventionChecker) EnterCreateTable(ctx *mysql.CreateT
}
func (checker *namingIndexConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
@@ -180,6 +186,9 @@ func (checker *namingIndexConventionChecker) EnterAlterTable(ctx *mysql.AlterTab
}
func (checker *namingIndexConventionChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
// Unique index naming convention should in advisor_naming_unique_key_convention.go
if ctx.UNIQUE_SYMBOL() != nil || ctx.FULLTEXT_SYMBOL() != nil || ctx.SPATIAL_SYMBOL() != nil {
return
diff --git a/backend/plugin/advisor/mysql/advisor_naming_table.go b/backend/plugin/advisor/mysql/advisor_naming_table.go
index 26dbb32d84..bbf2760725 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_table.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_table.go
@@ -83,6 +83,9 @@ func (checker *namingTableConventionChecker) generateAdvice() ([]advisor.Advice,
// EnterCreateTable is called when production createTable is entered.
func (checker *namingTableConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -93,6 +96,9 @@ func (checker *namingTableConventionChecker) EnterCreateTable(ctx *mysql.CreateT
// EnterAlterTable is called when production alterTable is entered.
func (checker *namingTableConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
@@ -116,6 +122,9 @@ func (checker *namingTableConventionChecker) EnterAlterTable(ctx *mysql.AlterTab
// EnterRenameTableStatement is called when production renameTableStatement is entered.
func (checker *namingTableConventionChecker) EnterRenameTableStatement(ctx *mysql.RenameTableStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
for _, pair := range ctx.AllRenamePair() {
if pair.TableName() == nil {
continue
diff --git a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
index d7f089e6ba..46b0da7e76 100644
--- a/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_naming_unique_key_convention.go
@@ -88,6 +88,9 @@ func (checker *namingUKConventionChecker) EnterQuery(ctx *mysql.QueryContext) {
}
func (checker *namingUKConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -113,6 +116,9 @@ func (checker *namingUKConventionChecker) EnterCreateTable(ctx *mysql.CreateTabl
}
func (checker *namingUKConventionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
@@ -175,6 +181,9 @@ func (checker *namingUKConventionChecker) EnterAlterTable(ctx *mysql.AlterTableC
}
func (checker *namingUKConventionChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
// only focus on unique index.
if ctx.UNIQUE_SYMBOL() == nil {
return
diff --git a/backend/plugin/advisor/mysql/advisor_online_migration.go b/backend/plugin/advisor/mysql/advisor_online_migration.go
index 77c0ea2b44..63f4bb47e9 100644
--- a/backend/plugin/advisor/mysql/advisor_online_migration.go
+++ b/backend/plugin/advisor/mysql/advisor_online_migration.go
@@ -104,6 +104,9 @@ type useGhostChecker struct {
}
func (c *useGhostChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
resource := base.SchemaResource{
Database: c.currentDatabase,
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
index d67064efbc..c41e7510ed 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_affected_row_limit.go
@@ -90,11 +90,17 @@ func (checker *statementAffectedRowLimitChecker) EnterQuery(ctx *mysql.QueryCont
// EnterUpdateStatement is called when production updateStatement is entered.
func (checker *statementAffectedRowLimitChecker) EnterUpdateStatement(ctx *mysql.UpdateStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.handleStmt(ctx.GetStart().GetLine())
}
// EnterDeleteStatement is called when production deleteStatement is entered.
func (checker *statementAffectedRowLimitChecker) EnterDeleteStatement(ctx *mysql.DeleteStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.handleStmt(ctx.GetStart().GetLine())
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_dml.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_dml.go
index eec36ed436..3ad5c820a1 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_dml.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_mix_dml.go
@@ -95,6 +95,9 @@ type table struct {
}
func (c *statementDisallowMixDMLChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
@@ -110,6 +113,9 @@ func (c *statementDisallowMixDMLChecker) EnterInsertStatement(ctx *mysql.InsertS
}
func (c *statementDisallowMixDMLChecker) EnterUpdateStatement(ctx *mysql.UpdateStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
var allTables []table
for _, tableRefCtx := range ctx.TableReferenceList().AllTableReference() {
tables, err := extractTableReference(tableRefCtx)
@@ -134,6 +140,9 @@ func (c *statementDisallowMixDMLChecker) EnterUpdateStatement(ctx *mysql.UpdateS
}
func (c *statementDisallowMixDMLChecker) EnterDeleteStatement(ctx *mysql.DeleteStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
var allTables []table
if ctx.TableRef() != nil {
tables, err := extractTableRef(ctx.TableRef())
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
index 5090743013..c81455ddf4 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_filesort.go
@@ -75,6 +75,9 @@ type disallowUsingFilesortChecker struct {
}
func (checker *disallowUsingFilesortChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
index 8e4a1a4a48..434a73c9d3 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_disallow_using_temporary.go
@@ -75,6 +75,9 @@ type disallowUsingTemporaryChecker struct {
}
func (checker *disallowUsingTemporaryChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
index c4618a010d..c28902d01d 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_dml_dry_run.go
@@ -81,16 +81,7 @@ type statementDmlDryRunChecker struct {
// EnterUpdateStatement is called when production updateStatement is entered.
func (checker *statementDmlDryRunChecker) EnterUpdateStatement(ctx *mysql.UpdateStatementContext) {
- if ctx.GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
- return
- }
- if ctx.GetParent().GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().GetParent().(*mysql.QueryContext); !ok {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
return
}
checker.handleStmt(ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx), ctx.GetStart().GetLine())
@@ -98,16 +89,7 @@ func (checker *statementDmlDryRunChecker) EnterUpdateStatement(ctx *mysql.Update
// EnterDeleteStatement is called when production deleteStatement is entered.
func (checker *statementDmlDryRunChecker) EnterDeleteStatement(ctx *mysql.DeleteStatementContext) {
- if ctx.GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
- return
- }
- if ctx.GetParent().GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().GetParent().(*mysql.QueryContext); !ok {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
return
}
checker.handleStmt(ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx), ctx.GetStart().GetLine())
@@ -115,16 +97,7 @@ func (checker *statementDmlDryRunChecker) EnterDeleteStatement(ctx *mysql.Delete
// EnterInsertStatement is called when production insertStatement is entered.
func (checker *statementDmlDryRunChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext) {
- if ctx.GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
- return
- }
- if ctx.GetParent().GetParent() == nil {
- return
- }
- if _, ok := ctx.GetParent().GetParent().(*mysql.QueryContext); !ok {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
return
}
checker.handleStmt(ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx), ctx.GetStart().GetLine())
diff --git a/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go b/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
index 42629d2eff..372e6ae9d3 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_join_strict_column_attrs.go
@@ -91,11 +91,17 @@ func (checker *statementJoinStrictColumnAttrsChecker) EnterQuery(ctx *mysql.Quer
checker.text = ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)
}
-func (checker *statementJoinStrictColumnAttrsChecker) EnterSelectStatement(_ *mysql.SelectStatementContext) {
+func (checker *statementJoinStrictColumnAttrsChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.isSelect = true
}
-func (checker *statementJoinStrictColumnAttrsChecker) ExitSelectStatement(_ *mysql.SelectStatementContext) {
+func (checker *statementJoinStrictColumnAttrsChecker) ExitSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.isSelect = false
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go b/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
index 07afc6293f..a189eacfb5 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_maximum_limit_value.go
@@ -77,11 +77,17 @@ func (checker *statementMaximumLimitValueChecker) EnterQuery(ctx *mysql.QueryCon
checker.text = ctx.GetParser().GetTokenStream().GetTextFromRuleContext(ctx)
}
-func (checker *statementMaximumLimitValueChecker) EnterSelectStatement(*mysql.SelectStatementContext) {
+func (checker *statementMaximumLimitValueChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.isSelect = true
}
-func (checker *statementMaximumLimitValueChecker) ExitSelectStatement(*mysql.SelectStatementContext) {
+func (checker *statementMaximumLimitValueChecker) ExitSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
checker.isSelect = false
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
index 99345bf431..4c946ec305 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_merge_alter_table.go
@@ -78,6 +78,9 @@ func (checker *statementMergeAlterTableChecker) EnterQuery(ctx *mysql.QueryConte
// EnterCreateTable is called when production createTable is entered.
func (checker *statementMergeAlterTableChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -92,6 +95,9 @@ func (checker *statementMergeAlterTableChecker) EnterCreateTable(ctx *mysql.Crea
// EnterAlterTable is called when production alterTable is entered.
func (checker *statementMergeAlterTableChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
index 29b0a8ecb0..e4f8a6c66f 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_query_minumum_plan_level.go
@@ -136,6 +136,9 @@ func (checker *statementQueryMinumumPlanLevelChecker) EnterQuery(ctx *mysql.Quer
}
func (checker *statementQueryMinumumPlanLevelChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
index fdc1ec763b..6ab06bda6c 100644
--- a/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
+++ b/backend/plugin/advisor/mysql/advisor_statement_select_full_table_scan.go
@@ -68,6 +68,9 @@ type statementSelectFullTableScanChecker struct {
}
func (checker *statementSelectFullTableScanChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if _, ok := ctx.GetParent().(*mysql.SimpleStatementContext); !ok {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
index 804aad5683..59829a0da1 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_disallow_commit.go
@@ -76,6 +76,10 @@ func (checker *statementDisallowCommitChecker) EnterQuery(ctx *mysql.QueryContex
// EnterTransactionStatement is called when production transactionStatement is entered.
func (checker *statementDisallowCommitChecker) EnterTransactionStatement(ctx *mysql.TransactionStatementContext) {
+ parent := ctx.GetParent().(*mysql.TransactionOrLockingStatementContext)
+ if !mysqlparser.IsTopMySQLRule(&parent.BaseParserRuleContext) {
+ return
+ }
if ctx.COMMIT_SYMBOL() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go b/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
index d3737ff017..073a578ab3 100644
--- a/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
+++ b/backend/plugin/advisor/mysql/advisor_stmt_where_required.go
@@ -73,6 +73,9 @@ func (checker *whereRequirementChecker) EnterQuery(ctx *mysql.QueryContext) {
// EnterDeleteStatement is called when production deleteStatement is entered.
func (checker *whereRequirementChecker) EnterDeleteStatement(ctx *mysql.DeleteStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.WhereClause() == nil || ctx.WhereClause().WHERE_SYMBOL() == nil {
checker.handleWhereClause(ctx.GetStart().GetLine())
}
@@ -80,6 +83,9 @@ func (checker *whereRequirementChecker) EnterDeleteStatement(ctx *mysql.DeleteSt
// EnterUpdateStatement is called when production updateStatement is entered.
func (checker *whereRequirementChecker) EnterUpdateStatement(ctx *mysql.UpdateStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.WhereClause() == nil || ctx.WhereClause().WHERE_SYMBOL() == nil {
checker.handleWhereClause(ctx.GetStart().GetLine())
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go b/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
index a7b562ede3..77a35f5860 100644
--- a/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_table_comment_convention.go
@@ -78,6 +78,9 @@ type tableCommentConventionChecker struct {
// EnterCreateTable is called when production createTable is entered.
func (checker *tableCommentConventionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
index 8410b99782..5df46dd4aa 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_partition.go
@@ -75,6 +75,9 @@ func (checker *tableDisallowPartitionChecker) EnterQuery(ctx *mysql.QueryContext
// EnterCreateDatabase is called when production createDatabase is entered.
func (checker *tableDisallowPartitionChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.PartitionClause() != nil && ctx.PartitionClause().PartitionTypeDef() != nil {
code = advisor.CreateTablePartition
@@ -93,6 +96,9 @@ func (checker *tableDisallowPartitionChecker) EnterCreateTable(ctx *mysql.Create
// EnterAlterTable is called when production alterTable is entered.
func (checker *tableDisallowPartitionChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.AlterTableActions().PartitionClause() != nil && ctx.AlterTableActions().PartitionClause().PartitionTypeDef() != nil {
code = advisor.CreateTablePartition
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go b/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
index 6c05eb3fc0..176b17598e 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_set_charset.go
@@ -70,6 +70,9 @@ func (checker *tableDisallowSetCharsetChecker) EnterQuery(ctx *mysql.QueryContex
}
func (checker *tableDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateTableOptions() != nil {
for _, option := range ctx.CreateTableOptions().AllCreateTableOption() {
if option.DefaultCharset() != nil {
@@ -86,6 +89,9 @@ func (checker *tableDisallowSetCharsetChecker) EnterCreateTable(ctx *mysql.Creat
}
func (checker *tableDisallowSetCharsetChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil || ctx.AlterTableActions().AlterCommandList() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go b/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
index 146b3b20fb..c549152024 100644
--- a/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
+++ b/backend/plugin/advisor/mysql/advisor_table_disallow_trigger.go
@@ -73,6 +73,9 @@ func (checker *tableDisallowTriggerChecker) EnterQuery(ctx *mysql.QueryContext)
// EnterCreateTrigger is to check the create trigger statement.
func (checker *tableDisallowTriggerChecker) EnterCreateTrigger(ctx *mysql.CreateTriggerContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.TriggerName() != nil {
code = advisor.CreateTableTrigger
diff --git a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
index 1ab9c7bca0..9b92c99cb4 100644
--- a/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
+++ b/backend/plugin/advisor/mysql/advisor_table_drop_naming_convention.go
@@ -76,6 +76,9 @@ type namingDropTableConventionChecker struct {
// EnterDropTable is called when production dropTable is entered.
func (checker *namingDropTableConventionChecker) EnterDropTable(ctx *mysql.DropTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRefList() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go b/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
index 8fa0693c7a..1104a29fb2 100644
--- a/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
+++ b/backend/plugin/advisor/mysql/advisor_table_no_duplicate_index.go
@@ -85,6 +85,9 @@ type duplicateIndex struct {
}
func (checker *tableNoDuplicateIndexChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -113,6 +116,9 @@ func (checker *tableNoDuplicateIndexChecker) EnterCreateTable(ctx *mysql.CreateT
}
func (checker *tableNoDuplicateIndexChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
@@ -174,6 +180,9 @@ func (checker *tableNoDuplicateIndexChecker) handleConstraintDef(tableName strin
}
func (checker *tableNoDuplicateIndexChecker) EnterCreateIndex(ctx *mysql.CreateIndexContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateIndexTarget() == nil || ctx.CreateIndexTarget().TableRef() == nil || ctx.CreateIndexTarget().KeyListVariants() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_no_fk.go b/backend/plugin/advisor/mysql/advisor_table_no_fk.go
index b914e20b89..c43b5af557 100644
--- a/backend/plugin/advisor/mysql/advisor_table_no_fk.go
+++ b/backend/plugin/advisor/mysql/advisor_table_no_fk.go
@@ -71,6 +71,9 @@ type tableNoFKChecker struct {
// EnterCreateTable is called when production createTable is entered.
func (checker *tableNoFKChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil || ctx.TableElementList() == nil {
return
}
@@ -86,6 +89,9 @@ func (checker *tableNoFKChecker) EnterCreateTable(ctx *mysql.CreateTableContext)
// EnterAlterTable is called when production alterTable is entered.
func (checker *tableNoFKChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_require_pk.go b/backend/plugin/advisor/mysql/advisor_table_require_pk.go
index 9cffca490f..9688b5c812 100644
--- a/backend/plugin/advisor/mysql/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/mysql/advisor_table_require_pk.go
@@ -74,6 +74,9 @@ type tableRequirePKChecker struct {
// EnterCreateTable is called when production createTable is entered.
func (checker *tableRequirePKChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableName() == nil {
return
}
@@ -125,6 +128,9 @@ func (checker *tableRequirePKChecker) handleTableConstraintDef(tableName string,
// EnterDropTable is called when production dropTable is entered.
func (checker *tableRequirePKChecker) EnterDropTable(ctx *mysql.DropTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRefList() == nil {
return
}
@@ -136,6 +142,9 @@ func (checker *tableRequirePKChecker) EnterDropTable(ctx *mysql.DropTableContext
// EnterAlterTable is called when production alterTable is entered.
func (checker *tableRequirePKChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableRef() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go b/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
index 8d1d8268a6..ef73d0bc73 100644
--- a/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
+++ b/backend/plugin/advisor/mysql/advisor_table_text_fields_total_length.go
@@ -77,6 +77,9 @@ type tableFieldsMaximumVarcharLengthChecker struct {
}
func (checker *tableFieldsMaximumVarcharLengthChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.TableElementList() == nil || ctx.TableName() == nil {
return
}
@@ -102,6 +105,9 @@ func (checker *tableFieldsMaximumVarcharLengthChecker) EnterCreateTable(ctx *mys
}
func (checker *tableFieldsMaximumVarcharLengthChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil {
return
}
diff --git a/backend/plugin/advisor/mysql/advisor_use_innodb.go b/backend/plugin/advisor/mysql/advisor_use_innodb.go
index fb89d73d3d..b8d6d3c9e0 100644
--- a/backend/plugin/advisor/mysql/advisor_use_innodb.go
+++ b/backend/plugin/advisor/mysql/advisor_use_innodb.go
@@ -74,6 +74,9 @@ type useInnoDBChecker struct {
// EnterCreateTable is called when production createTable is entered.
func (c *useInnoDBChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.CreateTableOptions() == nil {
return
}
@@ -94,6 +97,9 @@ func (c *useInnoDBChecker) EnterCreateTable(ctx *mysql.CreateTableContext) {
}
func (c *useInnoDBChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
if ctx.AlterTableActions() == nil || ctx.AlterTableActions().AlterCommandList() == nil {
return
}
@@ -126,6 +132,9 @@ func (c *useInnoDBChecker) EnterAlterTable(ctx *mysql.AlterTableContext) {
}
func (c *useInnoDBChecker) EnterSetStatement(ctx *mysql.SetStatementContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.StartOptionValueList() == nil {
return
diff --git a/backend/plugin/advisor/mysql/advisor_view_disallow_create.go b/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
index 2c80d8cacd..d72fd11343 100644
--- a/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
+++ b/backend/plugin/advisor/mysql/advisor_view_disallow_create.go
@@ -72,6 +72,9 @@ func (checker *viewDisallowCreateChecker) EnterQuery(ctx *mysql.QueryContext) {
}
func (checker *viewDisallowCreateChecker) EnterCreateView(ctx *mysql.CreateViewContext) {
+ if !mysqlparser.IsTopMySQLRule(&ctx.BaseParserRuleContext) {
+ return
+ }
code := advisor.Ok
if ctx.ViewName() != nil {
code = advisor.DisallowCreateView
diff --git a/backend/plugin/parser/mysql/mysql.go b/backend/plugin/parser/mysql/mysql.go
index ca2d144d0f..b9f9cd1731 100644
--- a/backend/plugin/parser/mysql/mysql.go
+++ b/backend/plugin/parser/mysql/mysql.go
@@ -301,3 +301,32 @@ func IsMySQLAffectedRowsStatement(statement string) bool {
return false
}
+
+// IsTopMySQLRule returns true if the given context is a top-level MySQL rule.
+func IsTopMySQLRule(ctx *antlr.BaseParserRuleContext) bool {
+ if ctx.GetParent() == nil {
+ return false
+ }
+ switch ctx.GetParent().(type) {
+ case *parser.SimpleStatementContext:
+ if ctx.GetParent().GetParent() == nil {
+ return false
+ }
+ if _, ok := ctx.GetParent().GetParent().(*parser.QueryContext); !ok {
+ return false
+ }
+ case *parser.CreateStatementContext, *parser.DropStatementContext, *parser.TransactionOrLockingStatementContext, *parser.AlterStatementContext:
+ if ctx.GetParent().GetParent() == nil {
+ return false
+ }
+ if ctx.GetParent().GetParent().GetParent() == nil {
+ return false
+ }
+ if _, ok := ctx.GetParent().GetParent().GetParent().(*parser.QueryContext); !ok {
+ return false
+ }
+ default:
+ return false
+ }
+ return true
+}