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

fix: ShardedRouting clone to clone slice of reference correctly #13265

Merged
merged 2 commits into from
Jun 8, 2023
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: 8 additions & 3 deletions go/test/endtoend/vtgate/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import (
"fmt"
"testing"

"vitess.io/vitess/go/test/endtoend/utils"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/utils"
)

func TestUnownedLookupInsertNull(t *testing.T) {
Expand Down Expand Up @@ -581,3 +579,10 @@ func TestUnicodeLooseMD5CaseInsensitive(t *testing.T) {

utils.AssertMatches(t, conn, "SELECT id1, id2 from t4 where id2 = 'Test'", `[[INT64(1) VARCHAR("test")]]`)
}

func TestJoinWithPredicateAndJoinOnDifferentVindex(t *testing.T) {
conn, closer := start(t)
defer closer()

utils.Exec(t, conn, "select t4.id1 from t4, t3 where t4.id2 = 'foo' and t4.id1 = t3.id6")
}
7 changes: 6 additions & 1 deletion go/vt/vtgate/planbuilder/operators/sharded_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"golang.org/x/exp/slices"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/slices2"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/engine"
Expand Down Expand Up @@ -150,7 +151,11 @@ func (tr *ShardedRouting) Clone() Routing {
selected = &t
}
return &ShardedRouting{
VindexPreds: slices.Clone(tr.VindexPreds),
VindexPreds: slices2.Map(tr.VindexPreds, func(from *VindexPlusPredicates) *VindexPlusPredicates {
// we do this to create a copy of the struct
p := *from
return &p
}),
Selected: selected,
keyspace: tr.keyspace,
RouteOpCode: tr.RouteOpCode,
Expand Down
97 changes: 97 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -8063,5 +8063,102 @@
"user.user_metadata"
]
}
},
{
"comment": "join query with lookup and join on different vindex column",
"query": "select u.id from user u, user_metadata um where u.name = 'foo' and u.id = um.user_id",
"v3-plan": {
"QueryType": "SELECT",
"Original": "select u.id from user u, user_metadata um where u.name = 'foo' and u.id = um.user_id",
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "L:0",
"JoinVars": {
"u_id": 0
},
"TableName": "`user`_user_metadata",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Equal",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select u.id from `user` as u where 1 != 1",
"Query": "select u.id from `user` as u where u.`name` = 'foo'",
"Table": "`user`",
"Values": [
"VARCHAR(\"foo\")"
],
"Vindex": "name_user_map"
},
{
"OperatorType": "Route",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select 1 from user_metadata as um where 1 != 1",
"Query": "select 1 from user_metadata as um where um.user_id = :u_id",
"Table": "user_metadata",
"Values": [
":u_id"
],
"Vindex": "user_index"
}
]
}
},
"gen4-plan": {
"QueryType": "SELECT",
"Original": "select u.id from user u, user_metadata um where u.name = 'foo' and u.id = um.user_id",
"Instructions": {
"OperatorType": "VindexLookup",
"Variant": "Equal",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Values": [
"VARCHAR(\"foo\")"
],
"Vindex": "name_user_map",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "IN",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `name`, keyspace_id from name_user_vdx where 1 != 1",
"Query": "select `name`, keyspace_id from name_user_vdx where `name` in ::__vals",
"Table": "name_user_vdx",
"Values": [
"::name"
],
"Vindex": "user_index"
},
{
"OperatorType": "Route",
"Variant": "ByDestination",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select u.id from `user` as u, user_metadata as um where 1 != 1",
"Query": "select u.id from `user` as u, user_metadata as um where u.`name` = 'foo' and u.id = um.user_id",
"Table": "`user`, user_metadata"
}
]
},
"TablesUsed": [
"user.user",
"user.user_metadata"
]
}
}
]