Skip to content

Commit

Permalink
add vschema ddl syntax to add/remove tables from unsharded keyspaces
Browse files Browse the repository at this point in the history
Since unsharded keyspaces don't have vindex definitions, implement
a new syntax for adding / removing tables from the vschema:

`alter vschema add table test_table`
`alter vschema drop table test_table`

Signed-off-by: Michael Demmer <[email protected]>
  • Loading branch information
demmer committed Dec 7, 2018
1 parent ae79ffd commit b55d155
Show file tree
Hide file tree
Showing 7 changed files with 1,698 additions and 1,545 deletions.
26 changes: 16 additions & 10 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,18 @@ type DDL struct {

// DDL strings.
const (
CreateStr = "create"
AlterStr = "alter"
DropStr = "drop"
RenameStr = "rename"
TruncateStr = "truncate"
FlushStr = "flush"
CreateVindexStr = "create vindex"
DropVindexStr = "drop vindex"
AddColVindexStr = "on table add vindex"
DropColVindexStr = "on table drop vindex"
CreateStr = "create"
AlterStr = "alter"
DropStr = "drop"
RenameStr = "rename"
TruncateStr = "truncate"
FlushStr = "flush"
CreateVindexStr = "create vindex"
DropVindexStr = "drop vindex"
AddVschemaTableStr = "add vschema table"
DropVschemaTableStr = "drop vschema table"
AddColVindexStr = "on table add vindex"
DropColVindexStr = "on table drop vindex"

// Vindex DDL param to specify the owner of a vindex
VindexOwnerStr = "owner"
Expand Down Expand Up @@ -795,6 +797,10 @@ func (node *DDL) Format(buf *TrackedBuffer) {
buf.Myprintf("alter vschema create vindex %v %v", node.VindexSpec.Name, node.VindexSpec)
case DropVindexStr:
buf.Myprintf("alter vschema drop vindex %v", node.VindexSpec.Name)
case AddVschemaTableStr:
buf.Myprintf("alter vschema add table %v", node.Table)
case DropVschemaTableStr:
buf.Myprintf("alter vschema drop table %v", node.Table)
case AddColVindexStr:
buf.Myprintf("alter vschema on %v add vindex %v (", node.Table, node.VindexSpec.Name)
for i, col := range node.VindexCols {
Expand Down
4 changes: 3 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ var (
}, {
input: "alter vschema drop vindex hash_vdx",
}, {
input: "alter vschema on a add vindex hash (id)",
input: "alter vschema add table a",
}, {
input: "alter vschema drop table a",
}, {
input: "alter vschema on a add vindex hash (id)",
}, {
Expand Down
Loading

0 comments on commit b55d155

Please sign in to comment.