Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3: support overlapping multi-column vindexes #4996

Merged
merged 1 commit into from
Aug 24, 2019
Merged
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
11 changes: 9 additions & 2 deletions go/vt/vtgate/planbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,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, fmt.Errorf("could not compute value for vindex or auto-inc column: %v", err)
}
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 @@ -1172,6 +1172,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": [
Copy link
Member

Choose a reason for hiding this comment

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

this would be easier to understand if we called this VindexValues while converting to JSON just like in the original Insert struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Makes sense. We should make a separate PR.

[
[
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 @@ -26,6 +26,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 @@ -165,6 +169,18 @@
}
]
},
"overlap_vindex": {
"column_vindexes": [
{
"column": "kid",
"name": "kid_index"
},
{
"columns": ["column_a", "kid"],
"name": "cola_kid_map"
}
]
},
"music_extra": {
"column_vindexes": [
{
Expand Down