Skip to content

Commit

Permalink
Support multi-col vindexes
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 28, 2024
1 parent e536072 commit ab83107
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,10 @@ func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspa
err error
)
if len(seqTable.ColumnVindexes[i].Columns) > 0 {
unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Columns[0]) // AutoIncrement definitions can only be on a single column
seqTable.ColumnVindexes[i].Columns[0] = unescapedColumn
for n := range seqTable.ColumnVindexes[i].Columns {
unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Columns[n])
seqTable.ColumnVindexes[i].Columns[n] = unescapedColumn
}
} else {
// This is the legacy vschema definition.
unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Column)
Expand Down
49 changes: 49 additions & 0 deletions go/vt/vtctl/workflow/traffic_switcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,55 @@ func TestGetTargetSequenceMetadata(t *testing.T) {
},
},
},
{
name: "sequence with table having mult-col vindex",
sourceVSchema: &vschema.Keyspace{
Vindexes: vindexes,
Tables: map[string]*vschema.Table{
"seq1": {
Type: "sequence",
},
},
},
targetVSchema: &vschema.Keyspace{
Vindexes: vindexes,
Tables: map[string]*vschema.Table{
table: {
ColumnVindexes: []*vschema.ColumnVindex{
{
Name: "xxhash",
Columns: []string{"col3", "col4"},
},
},
AutoIncrement: &vschema.AutoIncrement{
Column: "col1",
Sequence: fmt.Sprintf("%s.seq1", sourceKeyspace.KeyspaceName),
},
},
},
},
want: map[string]*sequenceMetadata{
"seq1": {
backingTableName: "seq1",
backingTableKeyspace: "source-ks",
backingTableDBName: "vt_source-ks",
usingTableName: unescapedTable,
usingTableDBName: "vt_targetks",
usingTableDefinition: &vschema.Table{
ColumnVindexes: []*vschema.ColumnVindex{
{
Columns: []string{"col3", "col4"},
Name: "xxhash",
},
},
AutoIncrement: &vschema.AutoIncrement{
Column: "col1",
Sequence: fmt.Sprintf("%s.seq1", sourceKeyspace.KeyspaceName),
},
},
},
},
},
{
name: "invalid table name",
sourceVSchema: &vschema.Keyspace{
Expand Down

0 comments on commit ab83107

Please sign in to comment.