Skip to content

Commit

Permalink
added plan test and e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Jun 7, 2023
1 parent d71c3d9 commit c5333af
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
15 changes: 12 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,12 @@ 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"
"vitess.io/vitess/go/vt/log"
)

func TestUnownedLookupInsertNull(t *testing.T) {
Expand Down Expand Up @@ -581,3 +580,13 @@ 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()

qr := utils.Exec(t, conn, "vexplain select /*vt+ planner=gen4 */ t4.id1 from t4, t3 where t4.id2 = 'foo' and t4.id1 = t3.id6")
log.Errorf("plan: \n%s\n", qr.Rows[0][0].ToString())

utils.Exec(t, conn, "select t4.id1 from t4, t3 where t4.id2 = 'foo' and t4.id1 = t3.id6")
}
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"
]
}
}
]

0 comments on commit c5333af

Please sign in to comment.