Skip to content

Commit

Permalink
feat: push down filter into the route when possible
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Feb 10, 2022
1 parent dfaf601 commit 22c7bca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
17 changes: 14 additions & 3 deletions go/vt/vtgate/planbuilder/physical/route_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@ func CreatePhysicalOperator(ctx *plancontext.PlanningContext, opTree abstract.Lo
if err != nil {
return nil, err
}
return &Filter{
Source: src,

filter := &Filter{
Predicates: op.Predicates,
}, nil
}

if route, ok := src.(*Route); ok {
// let's push the filter into the route
filter.Source = route.Source
route.Source = filter
return route, nil
}

filter.Source = src

return filter, nil
default:
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "invalid operator tree: %T", op)
}
Expand Down
32 changes: 9 additions & 23 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3915,29 +3915,15 @@ Gen4 plan same as above
"QueryType": "SELECT",
"Original": "select user.col from user_extra left outer join user on user_extra.user_id = user.id WHERE user.id IS NULL",
"Instructions": {
"OperatorType": "SimpleProjection",
"Columns": [
1
],
"Inputs": [
{
"OperatorType": "Filter",
"Predicate": "`user`.id is null",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.id, `user`.col from user_extra left join `user` on user_extra.user_id = `user`.id where 1 != 1",
"Query": "select `user`.id, `user`.col from user_extra left join `user` on user_extra.user_id = `user`.id",
"Table": "`user`, user_extra"
}
]
}
]
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.col from user_extra left join `user` on user_extra.user_id = `user`.id where 1 != 1",
"Query": "select `user`.col from user_extra left join `user` on user_extra.user_id = `user`.id where `user`.id is null",
"Table": "`user`, user_extra"
}
}
Gen4 plan same as above

0 comments on commit 22c7bca

Please sign in to comment.