Skip to content

Commit

Permalink
Merge pull request #4996 from planetscale/ss-multi-lookup
Browse files Browse the repository at this point in the history
v3: support overlapping multi-column vindexes
  • Loading branch information
sougou authored Aug 24, 2019
2 parents d14bade + 2d92543 commit 6467c98
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
11 changes: 9 additions & 2 deletions go/vt/vtgate/planbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,21 @@ func buildInsertShardedPlan(ins *sqlparser.Insert, table *vindexes.Table) (*engi
for colIdx, col := range colVindex.Columns {
routeValues[vIdx].Values[colIdx].Values = make([]sqltypes.PlanValue, len(rows))
colNum := findOrAddColumn(ins, col)
// swap bind variables
baseName := ":_" + col.CompliantName()
for rowNum, row := range rows {
innerpv, err := sqlparser.NewPlanValue(row[colNum])
if err != nil {
return nil, vterrors.Wrapf(err, "could not compute value for vindex or auto-inc column")
}
routeValues[vIdx].Values[colIdx].Values[rowNum] = innerpv
}
}
}
for _, colVindex := range eins.Table.ColumnVindexes {
for _, col := range colVindex.Columns {
colNum := findOrAddColumn(ins, col)
// swap bind variables
baseName := ":_" + col.CompliantName()
for rowNum, row := range rows {
row[colNum] = sqlparser.NewValArg([]byte(baseName + strconv.Itoa(rowNum)))
}
}
Expand Down
35 changes: 35 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,41 @@
}
}

# insert for overlapped vindex columns
"insert overlap_vindex (kid, column_a, column_b) VALUES (1,2,3)"
{
"Original": "insert overlap_vindex (kid, column_a, column_b) VALUES (1,2,3)",
"Instructions": {
"Opcode": "InsertSharded",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "insert into overlap_vindex(kid, column_a, column_b) values (:_kid0, :_column_a0, 3)",
"Values": [
[
[
1
]
],
[
[
2
],
[
1
]
]
],
"Table": "overlap_vindex",
"Prefix": "insert into overlap_vindex(kid, column_a, column_b) values ",
"Mid": [
"(:_kid0, :_column_a0, 3)"
]
}
}


# insert multiple rows in a multi column vindex table
"insert multicolvin (column_a, column_b, column_c, kid) VALUES (1,2,3,4), (5,6,7,8)"
{
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/schema_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"type": "lookup_test",
"owner": "multicolvin"
},
"cola_kid_map": {
"type": "lookup_test",
"owner": "overlap_vindex"
},
"name_user_map": {
"type": "multi",
"owner": "user"
Expand Down Expand Up @@ -212,6 +216,18 @@
}
]
},
"overlap_vindex": {
"column_vindexes": [
{
"column": "kid",
"name": "kid_index"
},
{
"columns": ["column_a", "kid"],
"name": "cola_kid_map"
}
]
},
"music_extra": {
"column_vindexes": [
{
Expand Down

0 comments on commit 6467c98

Please sign in to comment.