Skip to content

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

fix: exclude CREATE TABLE ... AS and CREATE TABLE ... LIKE statement for MySQL set CREATE TABLE line (#2435)

rebelicec129c802093b
diff --git a/plugin/parser/set_line_for_create_table_test.go b/plugin/parser/set_line_for_create_table_test.go
index 630f20e1f7..264b37cb46 100644
--- a/plugin/parser/set_line_for_create_table_test.go
+++ b/plugin/parser/set_line_for_create_table_test.go
@@ -103,6 +103,16 @@ func TestPGCreateTableSetLine(t *testing.T) {
func TestMySQLCreateTableSetLine(t *testing.T) {
tests := []setLineTestData{
+ {
+ statement: "CREATE TABLE t as select * from t1",
+ columnLineList: []int{},
+ constraintLineList: []int{},
+ },
+ {
+ statement: "CREATE TABLE t like t1",
+ columnLineList: []int{},
+ constraintLineList: []int{},
+ },
{
statement: `-- this is the first line.
CREATE TABLE t(
diff --git a/plugin/parser/utils.go b/plugin/parser/utils.go
index a736f471ce..d146f2bcc9 100644
--- a/plugin/parser/utils.go
+++ b/plugin/parser/utils.go
@@ -58,5 +58,9 @@ func SetLineForCreateTableStmt(engineType EngineType, node *ast.CreateTableStmt)
// This is a temporary function. Because we do not convert tidb AST to our AST. So we have to implement this.
// TODO(rebelice): remove it.
func SetLineForMySQLCreateTableStmt(node *tidbast.CreateTableStmt) error {
+ // exclude CREATE TABLE ... AS and CREATE TABLE ... LIKE statement.
+ if len(node.Cols) == 0 {
+ return nil
+ }
return newTokenizer(node.Text()).setLineForMySQLCreateTableStmt(node)
}