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

[release-18.0] bugfix: do not rewrite an expression twice (#14641) #14643

Merged
merged 2 commits into from
Nov 30, 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
4 changes: 0 additions & 4 deletions go/vt/vtgate/planbuilder/operators/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ func (a *Aggregator) findColInternal(ctx *plancontext.PlanningContext, ae *sqlpa
if offset >= 0 {
return offset, err
}
expr, err = a.DT.RewriteExpression(ctx, expr)
if err != nil {
return 0, err
}

// Aggregator is little special and cannot work if the input offset are not matched with the aggregation columns.
// So, before pushing anything from above the aggregator offset planning needs to be completed.
Expand Down
84 changes: 84 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/aggr_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6004,5 +6004,89 @@
"user.user"
]
}
},
{
"comment": "Group by aggregated column should not be a problem",
"query": "SELECT b.col FROM music AS b JOIN (SELECT MIN(bb.id) AS min_id, MAX(bb.id) AS max_id FROM user AS bb) AS foobars WHERE b.id > foobars.min_id GROUP BY b.col",
"plan": {
"QueryType": "SELECT",
"Original": "SELECT b.col FROM music AS b JOIN (SELECT MIN(bb.id) AS min_id, MAX(bb.id) AS max_id FROM user AS bb) AS foobars WHERE b.id > foobars.min_id GROUP BY b.col",
"Instructions": {
"OperatorType": "Aggregate",
"Variant": "Ordered",
"GroupBy": "(0|1)",
"ResultColumns": 1,
"Inputs": [
{
"OperatorType": "Sort",
"Variant": "Memory",
"OrderBy": "(0|1) ASC",
"Inputs": [
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "R:0,R:1",
"JoinVars": {
"foobars_min_id": 0
},
"TableName": "`user`_music",
"Inputs": [
{
"OperatorType": "Aggregate",
"Variant": "Ordered",
"GroupBy": "(0|1)",
"Inputs": [
{
"OperatorType": "SimpleProjection",
"Columns": [
0,
3
],
"Inputs": [
{
"OperatorType": "Aggregate",
"Variant": "Scalar",
"Aggregates": "min(0|2) AS min_id, max(1|2) AS max_id, any_value(3)",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select min(bb.id) as min_id, max(bb.id) as max_id, weight_string(bb.id), weight_string(min(bb.id)) from `user` as bb where 1 != 1 group by weight_string(bb.id)",
"OrderBy": "0 ASC",
"Query": "select min(bb.id) as min_id, max(bb.id) as max_id, weight_string(bb.id), weight_string(min(bb.id)) from `user` as bb group by weight_string(bb.id) order by min(bb.id) asc",
"Table": "`user`"
}
]
}
]
}
]
},
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select b.col, weight_string(b.col) from music as b where 1 != 1 group by b.col, weight_string(b.col)",
"Query": "select b.col, weight_string(b.col) from music as b where b.id > :foobars_min_id group by b.col, weight_string(b.col)",
"Table": "music"
}
]
}
]
}
]
},
"TablesUsed": [
"user.music",
"user.user"
]
}
}
]
Loading