Skip to content

Commit

Permalink
planbuilder: push column on the correct side
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 14, 2023
1 parent 83f8693 commit 61a1344
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 549 deletions.
15 changes: 8 additions & 7 deletions go/test/endtoend/vtgate/queries/derived/derived_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,23 @@ func TestDerivedTableColumns(t *testing.T) {
// We do this by not using the apply join we usually use, and instead use the hash join engine primitive
// These tests exercise these situations
func TestDerivedTablesWithLimit(t *testing.T) {
t.Skip("failing")
// We need full type info before planning this, so we wait for the schema tracker
require.NoError(t,
utils.WaitForAuthoritative(t, keyspaceName, "user", clusterInstance.VtgateProcess.ReadVSchema))

mcmp, closer := start(t)
defer closer()

mcmp.AssertMatches(
`SELECT u.id FROM
mcmp.Exec("insert into user(id, name) values(6,'pikachu')")

mcmp.AssertMatchesNoOrder(
`SELECT u.id, m.id FROM
(SELECT id, name FROM user LIMIT 10) AS u JOIN
(SELECT id, user_id FROM music LIMIT 10) as m on u.id = m.user_id`,
`[[INT64(5)] [INT64(4)] [INT64(3)] [INT64(2)] [INT64(1)]]`)
`[[INT64(1) INT64(1)] [INT64(5) INT64(2)] [INT64(1) INT64(3)] [INT64(2) INT64(4)] [INT64(3) INT64(5)] [INT64(5) INT64(7)] [INT64(4) INT64(6)]]`)

mcmp.AssertMatches(
`SELECT u.id FROM user AS u LEFT JOIN
mcmp.AssertMatchesNoOrder(
`SELECT u.id, m.id FROM user AS u LEFT JOIN
(SELECT id, user_id FROM music LIMIT 10) as m on u.id = m.user_id`,
`[[INT64(5)] [INT64(4)] [INT64(3)] [INT64(2)] [INT64(1)]]`)
`[[INT64(1) INT64(1)] [INT64(5) INT64(2)] [INT64(1) INT64(3)] [INT64(2) INT64(4)] [INT64(3) INT64(5)] [INT64(5) INT64(7)] [INT64(4) INT64(6)] [INT64(6) NULL]]`)
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (hj *HashJoin) planOffsets(ctx *plancontext.PlanningContext) ops.Operator {
for _, cmp := range hj.JoinComparisons {
lOffset := hj.LHS.AddColumn(ctx, true, false, aeWrap(cmp.LHS))
hj.LHSKeys = append(hj.LHSKeys, lOffset)
rOffset := hj.LHS.AddColumn(ctx, true, false, aeWrap(cmp.RHS))
rOffset := hj.RHS.AddColumn(ctx, true, false, aeWrap(cmp.RHS))
hj.RHSKeys = append(hj.RHSKeys, rOffset)
}

Expand Down
20 changes: 10 additions & 10 deletions go/vt/vtgate/planbuilder/testdata/from_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,7 @@
"Variant": "HashLeftJoin",
"Collation": "binary",
"ComparisonType": "INT16",
"JoinColumnIndexes": "-3",
"JoinColumnIndexes": "-2",
"Predicate": "`user`.col = ue.col",
"TableName": "`user`_user_extra",
"Inputs": [
Expand All @@ -4079,8 +4079,8 @@
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.col, ue.col, id from `user` where 1 != 1",
"Query": "select `user`.col, ue.col, id from `user`",
"FieldQuery": "select `user`.col, id from `user` where 1 != 1",
"Query": "select `user`.col, id from `user`",
"Table": "`user`"
},
{
Expand All @@ -4094,8 +4094,8 @@
"Name": "user",
"Sharded": true
},
"FieldQuery": "select 1 from (select col from user_extra where 1 != 1) as ue where 1 != 1",
"Query": "select 1 from (select col from user_extra) as ue limit :__upper_limit",
"FieldQuery": "select col from (select col from user_extra where 1 != 1) as ue where 1 != 1",
"Query": "select col from (select col from user_extra) as ue limit :__upper_limit",
"Table": "user_extra"
}
]
Expand Down Expand Up @@ -4128,7 +4128,7 @@
"Variant": "HashJoin",
"Collation": "binary",
"ComparisonType": "INT16",
"JoinColumnIndexes": "-1,3",
"JoinColumnIndexes": "-1,2",
"Predicate": "u.col = ue.col",
"TableName": "`user`_user_extra",
"Inputs": [
Expand All @@ -4143,8 +4143,8 @@
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id, col, ue.col from (select id, col from `user` where 1 != 1) as u where 1 != 1",
"Query": "select id, col, ue.col from (select id, col from `user`) as u limit :__upper_limit",
"FieldQuery": "select id, col from (select id, col from `user` where 1 != 1) as u where 1 != 1",
"Query": "select id, col from (select id, col from `user`) as u limit :__upper_limit",
"Table": "`user`"
}
]
Expand All @@ -4160,8 +4160,8 @@
"Name": "user",
"Sharded": true
},
"FieldQuery": "select col, user_id, user_id from (select col, user_id from user_extra where 1 != 1) as ue where 1 != 1",
"Query": "select col, user_id, user_id from (select col, user_id from user_extra) as ue limit :__upper_limit",
"FieldQuery": "select col, user_id from (select col, user_id from user_extra where 1 != 1) as ue where 1 != 1",
"Query": "select col, user_id from (select col, user_id from user_extra) as ue limit :__upper_limit",
"Table": "user_extra"
}
]
Expand Down
Loading

0 comments on commit 61a1344

Please sign in to comment.