Skip to content

Commit

Permalink
planbuilder: push down ordering through filter (#14583)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay authored Nov 22, 2023
1 parent ae8d61e commit 2d0c9c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
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

0 comments on commit 2d0c9c1

Please sign in to comment.