Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planbuilder: push down ordering through filter #14583

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ func tryPushOrdering(ctx *plancontext.PlanningContext, in *Ordering) (ops.Operat
switch src := in.Source.(type) {
case *Route:
return rewrite.Swap(in, src, "push ordering under route")
case *Filter:
return rewrite.Swap(in, src, "push ordering under filter")
case *ApplyJoin:
if canPushLeft(ctx, src, in.Order) {
// ApplyJoin is stable in regard to the columns coming from the LHS,
Expand Down
73 changes: 33 additions & 40 deletions go/vt/vtgate/planbuilder/testdata/postprocess_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2021,54 +2021,47 @@
"QueryType": "SELECT",
"Original": "select a.tcol1 from user a join music b where a.tcol1 = b.tcol2 group by a.tcol1 having repeat(a.tcol1,min(a.id)) like \"A\\%B\" order by a.tcol1",
"Instructions": {
"OperatorType": "Sort",
"Variant": "Memory",
"OrderBy": "(0|2) ASC",
"OperatorType": "Filter",
"Predicate": "repeat(a.tcol1, min(a.id)) like 'A\\%B'",
"ResultColumns": 1,
"Inputs": [
{
"OperatorType": "Filter",
"Predicate": "repeat(a.tcol1, min(a.id)) like 'A\\%B'",
"OperatorType": "Aggregate",
"Variant": "Ordered",
"Aggregates": "min(1|3) AS min(a.id)",
"GroupBy": "(0|2)",
"Inputs": [
{
"OperatorType": "Aggregate",
"Variant": "Ordered",
"Aggregates": "min(1|3) AS min(a.id)",
"GroupBy": "(0|2)",
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "L:1,L:0,L:2,L:3",
"JoinVars": {
"a_tcol1": 1
},
"TableName": "`user`_music",
"Inputs": [
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "L:1,L:0,L:2,L:3",
"JoinVars": {
"a_tcol1": 1
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select min(a.id), a.tcol1, weight_string(a.tcol1), weight_string(a.id) from `user` as a where 1 != 1 group by a.tcol1, weight_string(a.tcol1), weight_string(a.id)",
"OrderBy": "(1|2) ASC",
"Query": "select min(a.id), a.tcol1, weight_string(a.tcol1), weight_string(a.id) from `user` as a group by a.tcol1, weight_string(a.tcol1), weight_string(a.id) order by a.tcol1 asc",
"Table": "`user`"
},
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TableName": "`user`_music",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select min(a.id), a.tcol1, weight_string(a.tcol1), weight_string(a.id) from `user` as a where 1 != 1 group by a.tcol1, weight_string(a.tcol1), weight_string(a.id)",
"OrderBy": "(1|2) ASC",
"Query": "select min(a.id), a.tcol1, weight_string(a.tcol1), weight_string(a.id) from `user` as a group by a.tcol1, weight_string(a.tcol1), weight_string(a.id) order by a.tcol1 asc",
"Table": "`user`"
},
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select 1 from music as b where 1 != 1 group by .0",
"Query": "select 1 from music as b where b.tcol2 = :a_tcol1 group by .0",
"Table": "music"
}
]
"FieldQuery": "select 1 from music as b where 1 != 1 group by .0",
"Query": "select 1 from music as b where b.tcol2 = :a_tcol1 group by .0",
"Table": "music"
}
]
}
Expand Down
Loading