Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,22 +739,31 @@ type DDL struct {

// VindexCols is set for AddColVindexStr.
VindexCols []ColIdent

// VschemaUpdates are key=value expressions to set vschema values like `Authoritative`
VschemaUpdates UpdateExprs

// VschemaCol is set for add/drop a vschema column
VschemaCol *ColumnDefinition
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per dweitzman
Looks like today vitess doesn't need to know how to parse column information from alter ddls.
A question to consider: when adding support for parsing some detail from a vschema alter statement, is it worthwhile to try to align the AST with the direction it would go in if trying to support parsing mysql schema alter statements?
Here's the alter AST in the mysql 8 code, for reference: https://github.com/mysql/mysql-server/blob/8e797a5d6eb3a87f16498edcb7261a75897babae/sql/sql_alter.h#L168.

not seeing a column order use case in vschema columns, and since the longer term solution is to let vtgate figure out the correct schema cross shards themselves, i'm not going to implement that in this PR.

}

// DDL strings.
const (
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"
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"
AddVschemaColStr = "on table add column"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per dweitzman
Nit: columns in a vindex is not necessarily authoritative. Depends whether the table is marked as having authoritative columns. Maybe something like "AddVschemaColStr" would be a more accurate name than "AddAuthColumnStr"

DropVschemaColStr = "on table drop column"
SetVschemaUpdatesStr = "on table set"

// Vindex DDL param to specify the owner of a vindex
VindexOwnerStr = "owner"
Expand Down Expand Up @@ -813,6 +822,19 @@ func (node *DDL) Format(buf *TrackedBuffer) {
}
case DropColVindexStr:
buf.Myprintf("alter vschema on %v drop vindex %v", node.Table, node.VindexSpec.Name)
case AddVschemaColStr:
buf.Myprintf("alter vschema on %v add column %v ", node.Table, node.VschemaCol.Name)
node.VschemaCol.Type.Format(buf)
case DropVschemaColStr:
buf.Myprintf("alter vschema on %v drop column %v", node.Table, node.VschemaCol.Name)
case SetVschemaUpdatesStr:
buf.Myprintf("alter vschema on %v set ", node.Table)
for i, update := range node.VschemaUpdates {
if i != 0 {
buf.Myprintf(", ")
}
update.Format(buf)
}
default:
buf.Myprintf("%s table %v", node.Action, node.Table)
}
Expand Down
16 changes: 16 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,20 @@ var (
}, {
input: "alter vschema on a drop vindex `add`",
output: "alter vschema on a drop vindex `add`",
}, {
input: "alter vschema on a add column name varchar(16)",
}, {
input: "alter vschema on a drop column name",
}, {
input: "alter vschema on a set column_list_authoritative = true",
}, {
input: "alter vschema on a set column_list_authoritative=true",
output: "alter vschema on a set column_list_authoritative = true",
}, {
input: "alter vschema on a set column_list_authoritative = false",
}, {
input: "alter vschema on a set column_list_authoritative=false",
output: "alter vschema on a set column_list_authoritative = false",
}, {
input: "create index a on b",
output: "alter table b",
Expand Down Expand Up @@ -1266,6 +1280,8 @@ var (
input: "show vschema vindexes",
}, {
input: "show vschema vindexes on t",
}, {
input: "show vschema columns on t",
}, {
input: "show warnings",
output: "show warnings",
Expand Down
Loading