Skip to content

Commit

Permalink
Merge pull request #3335 from tinyspeck/add-support-for-truncate
Browse files Browse the repository at this point in the history
Add support for TRUNCATE as DDL statement
  • Loading branch information
sougou authored Oct 25, 2017
2 parents f6ed5b8 + cced35b commit 9c4cabd
Show file tree
Hide file tree
Showing 9 changed files with 2,037 additions and 1,954 deletions.
14 changes: 14 additions & 0 deletions data/test/tabletserver/ddl_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,17 @@
{
"Action": "alter", "TableName": "a", "NewTable": "a"
}

# truncate
"truncate a"
{
"PlanID": "DDL",
"TableName": "a"
}

# truncate
"truncate table a"
{
"PlanID": "DDL",
"TableName": "a"
}
7 changes: 0 additions & 7 deletions data/test/tabletserver/exec_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1192,13 +1192,6 @@
"TableName": ""
}

# truncate
"truncate a"
{
"PlanID": "OTHER_ADMIN",
"TableName": ""
}

# table not found select
"select * from aaaa"
"table aaaa not found in schema"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/schemamanager/tablet_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDD
}
for _, ddl := range parsedDDLs {
switch ddl.Action {
case sqlparser.DropStr, sqlparser.CreateStr:
case sqlparser.DropStr, sqlparser.CreateStr, sqlparser.TruncateStr:
continue
}
tableName := ddl.Table.Name.String()
Expand Down
6 changes: 6 additions & 0 deletions go/vt/schemamanager/tablet_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func TestTabletExecutorValidate(t *testing.T) {
t.Fatalf("executor.Validate should fail, change a table more than 2,000,000 rows")
}

if err := executor.Validate(ctx, []string{
"TRUNCATE TABLE test_table_04",
}); err != nil {
t.Fatalf("executor.Validate should succeed, drop a table with more than 2,000,000 rows is allowed")
}

if err := executor.Validate(ctx, []string{
"DROP TABLE test_table_04",
}); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ func (node *Set) WalkSubtree(visit Visit) error {
)
}

// DDL represents a CREATE, ALTER, DROP or RENAME statement.
// Table is set for AlterStr, DropStr, RenameStr
// DDL represents a CREATE, ALTER, DROP, RENAME or TRUNCATE statement.
// Table is set for AlterStr, DropStr, RenameStr, TruncateStr
// NewName is set for AlterStr, CreateStr, RenameStr.
type DDL struct {
Action string
Expand All @@ -568,10 +568,11 @@ type DDL struct {

// DDL strings.
const (
CreateStr = "create"
AlterStr = "alter"
DropStr = "drop"
RenameStr = "rename"
CreateStr = "create"
AlterStr = "alter"
DropStr = "drop"
RenameStr = "rename"
TruncateStr = "truncate"
)

// Format formats the node.
Expand Down
5 changes: 4 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,12 @@ var (
}, {
input: "explain foobar",
output: "otherread",
}, {
input: "truncate table foo",
output: "truncate table foo",
}, {
input: "truncate foo",
output: "otheradmin",
output: "truncate table foo",
}, {
input: "repair foo",
output: "otheradmin",
Expand Down
Loading

0 comments on commit 9c4cabd

Please sign in to comment.