Skip to content

Commit

Permalink
test: add e2e test to verify straight join changes
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Mar 20, 2024
1 parent fca5ba9 commit dbb73a8
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 9 deletions.
27 changes: 27 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,30 @@ func TestAlterTableWithView(t *testing.T) {

mcmp.AssertMatches("select * from v1", `[[INT64(1) INT64(1)]]`)
}

// TestStraightJoin tests that Vitess respects the ordering of join in a STRAIGHT JOIN query.
func TestStraightJoin(t *testing.T) {
utils.SkipIfBinaryIsBelowVersion(t, 20, "vtgate")
mcmp, closer := start(t)
defer closer()

mcmp.Exec("insert into tbl(id, unq_col, nonunq_col) values (1,0,10), (2,10,10), (3,4,20), (4,30,20), (5,40,10)")
mcmp.Exec(`insert into t1(id1, id2) values (10, 11), (20, 13)`)

mcmp.AssertMatchesNoOrder("select tbl.unq_col, tbl.nonunq_col, t1.id2 from t1 join tbl where t1.id1 = tbl.nonunq_col",
`[[INT64(0) INT64(10) INT64(11)] [INT64(10) INT64(10) INT64(11)] [INT64(4) INT64(20) INT64(13)] [INT64(40) INT64(10) INT64(11)] [INT64(30) INT64(20) INT64(13)]]`,
)
// Verify that in a normal join query, vitess joins tbl with t1.
res, err := mcmp.VtConn.ExecuteFetch("vexplain plan select tbl.unq_col, tbl.nonunq_col, t1.id2 from t1 join tbl where t1.id1 = tbl.nonunq_col", 100, false)
require.NoError(t, err)
require.Contains(t, fmt.Sprintf("%v", res.Rows), "tbl_t1")

// Test the same query with a straight join
mcmp.AssertMatchesNoOrder("select tbl.unq_col, tbl.nonunq_col, t1.id2 from t1 straight_join tbl where t1.id1 = tbl.nonunq_col",
`[[INT64(0) INT64(10) INT64(11)] [INT64(10) INT64(10) INT64(11)] [INT64(4) INT64(20) INT64(13)] [INT64(40) INT64(10) INT64(11)] [INT64(30) INT64(20) INT64(13)]]`,
)
// Verify that in a straight join query, vitess joins t1 with tbl.
res, err = mcmp.VtConn.ExecuteFetch("vexplain plan select tbl.unq_col, tbl.nonunq_col, t1.id2 from t1 straight_join tbl where t1.id1 = tbl.nonunq_col", 100, false)
require.NoError(t, err)
require.Contains(t, fmt.Sprintf("%v", res.Rows), "t1_tbl")
}
69 changes: 60 additions & 9 deletions go/vt/vtgate/planbuilder/testdata/onecase.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
[
{
"comment": "Add your test case here for debugging and run go test -run=One.",
"query": "",
"plan": {

}
}
]
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "R:0,R:1,L:0",
"JoinVars": {
"t1_id1": 1
},
"TableName": "t1_tbl",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "ks_misc",
"Sharded": true
},
"FieldQuery": "select t1.id2, t1.id1 from t1 where 1 != 1",
"Query": "select t1.id2, t1.id1 from t1",
"Table": "t1"
},
{
"OperatorType": "VindexLookup",
"Variant": "EqualUnique",
"Keyspace": {
"Name": "ks_misc",
"Sharded": true
},
"Values": [
":t1_id1"
],
"Vindex": "unq_vdx",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "IN",
"Keyspace": {
"Name": "ks_misc",
"Sharded": true
},
"FieldQuery": "select unq_col, keyspace_id from unq_idx where 1 != 1",
"Query": "select unq_col, keyspace_id from unq_idx where unq_col in ::__vals",
"Table": "unq_idx",
"Values": [
"::unq_col"
],
"Vindex": "hash"
},
{
"OperatorType": "Route",
"Variant": "ByDestination",
"Keyspace": {
"Name": "ks_misc",
"Sharded": true
},
"FieldQuery": "select tbl.unq_col, tbl.nonunq_col from tbl where 1 != 1",
"Query": "select tbl.unq_col, tbl.nonunq_col from tbl where tbl.unq_col = :t1_id1",
"Table": "tbl"
}
]
}

0 comments on commit dbb73a8

Please sign in to comment.