Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed Aug 25, 2024
1 parent 9034630 commit 8a31339
Showing 1 changed file with 24 additions and 70 deletions.
94 changes: 24 additions & 70 deletions session/session_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,87 +25,41 @@ func Test_checkDDLInstantMySQL(t *testing.T) {
parser := parser.New()
sessionVars := variable.NewSessionVars()
parser.SetSQLMode(sessionVars.SQLMode)
sql := "alter table t1 add column c1 int;"
stmts, _, err := parser.Parse(sql, "", "")
if err != nil {
t.Error(err)
}

table := &TableInfo{Name: "t1",
Fields: []FieldInfo{
{Field: "c1", Extra: ""},
{Field: "c2", Extra: "VIRTUAL"},
{Field: "c3", Extra: "STORED"}}}

for _, stmtNode := range stmts {
switch node := stmtNode.(type) {
case *ast.AlterTableStmt:
canInstant := checkDDLInstantMySQL57(node)
if canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}

canInstant = checkDDLInstantMySQL80(node, table, 80000)
if !canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}

}
tests := []struct {
sql string
mysql57 bool
mysql80 bool
}{
{"alter table t1 add column c1 int;", false, true},
{"ALTER TABLE t1 ADD COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL;", true, true},
{"ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;", false, false},
{"ALTER TABLE t1 ADD COLUMN c3 INT GENERATED ALWAYS AS (c1 + 1) STORED;", false, false},
}

sql = "ALTER TABLE t1 ADD COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL;"
stmts, _, err = parser.Parse(sql, "", "")
if err != nil {
t.Error(err)
}

for _, stmtNode := range stmts {
switch node := stmtNode.(type) {
case *ast.AlterTableStmt:
canInstant := checkDDLInstantMySQL57(node)
if !canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}

canInstant = checkDDLInstantMySQL80(node, table, 80000)
if !canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}
for _, test := range tests {
stmts, _, err := parser.Parse(test.sql, "", "")
if err != nil {
t.Error(err)
}
}

sql = "ALTER TABLE t1 ADD COLUMN c3 INT GENERATED ALWAYS AS (c1 + 1) STORED;"
stmts, _, err = parser.Parse(sql, "", "")
if err != nil {
t.Error(err)
}

for _, stmtNode := range stmts {
switch node := stmtNode.(type) {
case *ast.AlterTableStmt:
canInstant := checkDDLInstantMySQL57(node)
if canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}
for _, stmtNode := range stmts {
switch node := stmtNode.(type) {
case *ast.AlterTableStmt:
canInstant := checkDDLInstantMySQL57(node)
if canInstant != test.mysql57 {
t.Errorf("canInstant is %v, but excepted %v: sql: %v", canInstant, test.mysql57, test.sql)
}

canInstant = checkDDLInstantMySQL80(node, table, 80000)
if canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
}
}
}

sql = "ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;"
stmts, _, err = parser.Parse(sql, "", "")
if err != nil {
t.Error(err)
}
for _, stmtNode := range stmts {
switch node := stmtNode.(type) {
case *ast.AlterTableStmt:
canInstant := checkDDLInstantMySQL80(node, table, 80000)
if canInstant {
t.Errorf("canInstant is %v, but excepted %v", canInstant, !canInstant)
canInstant = checkDDLInstantMySQL80(node, table, 80000)
if canInstant != test.mysql80 {
t.Errorf("canInstant is %v, but excepted %v: sql: %v", canInstant, test.mysql57, test.sql)
}
}
}
}
Expand Down

0 comments on commit 8a31339

Please sign in to comment.