Skip to content

Commit

Permalink
fix: pushing of ORDER BY by recursive deps, since we can split a deri…
Browse files Browse the repository at this point in the history
…ved table across a join

Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Apr 19, 2024
1 parent ff6ca02 commit 2f338ca
Show file tree
Hide file tree
Showing 3 changed files with 574 additions and 89 deletions.
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func pushOrderingUnderAggr(ctx *plancontext.PlanningContext, order *Ordering, ag
func canPushLeft(ctx *plancontext.PlanningContext, aj *ApplyJoin, order []OrderBy) bool {
lhs := TableID(aj.LHS)
for _, order := range order {
deps := ctx.SemTable.DirectDeps(order.Inner.Expr)
deps := ctx.SemTable.RecursiveDeps(order.Inner.Expr)
if !deps.IsSolvedBy(lhs) {
return false
}
Expand Down
50 changes: 50 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -655,5 +655,55 @@
"user.user"
]
}
},
{
"comment": "Derived table split across two shards, and ordered by both",
"query": "select * from (select u.foo, ue.bar from user u, user_extra ue) poo order by poo.bar, poo.foo",
"plan": {
"QueryType": "SELECT",
"Original": "select * from (select u.foo, ue.bar from user u, user_extra ue) poo order by poo.bar, poo.foo",
"Instructions": {
"OperatorType": "Sort",
"Variant": "Memory",
"OrderBy": "(1|2) ASC, (0|3) ASC",
"ResultColumns": 2,
"Inputs": [
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "L:0,R:0,R:1,L:1",
"TableName": "`user`_user_extra",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select foo, weight_string(foo) from (select u.foo from `user` as u where 1 != 1) as poo where 1 != 1",
"Query": "select foo, weight_string(foo) from (select u.foo from `user` as u) as poo",
"Table": "`user`"
},
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select bar, weight_string(bar) from (select ue.bar from user_extra as ue where 1 != 1) as poo where 1 != 1",
"Query": "select bar, weight_string(bar) from (select ue.bar from user_extra as ue) as poo",
"Table": "user_extra"
}
]
}
]
},
"TablesUsed": [
"user.user",
"user.user_extra"
]
}
}
]
Loading

0 comments on commit 2f338ca

Please sign in to comment.