mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-18 07:34:19 +01:00
resolve aggregates from orderby as well
This commit is contained in:
@@ -20,6 +20,9 @@ impl OperatorIdCounter {
|
||||
}
|
||||
|
||||
fn resolve_aggregates(expr: &ast::Expr, aggs: &mut Vec<Aggregate>) {
|
||||
if aggs.iter().any(|a| a.original_expr == *expr) {
|
||||
return;
|
||||
}
|
||||
match expr {
|
||||
ast::Expr::FunctionCall { name, args, .. } => {
|
||||
let args_count = if let Some(args) = &args {
|
||||
@@ -433,6 +436,9 @@ pub fn prepare_select_plan<'a>(schema: &Schema, select: ast::Select) -> Result<P
|
||||
};
|
||||
|
||||
bind_column_references(&mut expr, &plan.referenced_tables)?;
|
||||
if let Some(aggs) = &mut plan.aggregates {
|
||||
resolve_aggregates(&expr, aggs);
|
||||
}
|
||||
|
||||
key.push((
|
||||
expr,
|
||||
|
||||
@@ -115,4 +115,17 @@ Dennis|Ward|1
|
||||
Whitney|Walker|1
|
||||
Robert|Villanueva|1
|
||||
Cynthia|Thomas|1
|
||||
Brandon|Tate|1}
|
||||
Brandon|Tate|1}
|
||||
|
||||
do_execsql_test order-by-case-insensitive-aggregate {
|
||||
select u.first_name, sum(u.age) from users u group by u.first_name order by SUM(u.aGe) desc limit 10;
|
||||
} {Michael|11204
|
||||
David|8758
|
||||
Robert|8109
|
||||
Jennifer|7700
|
||||
John|7299
|
||||
Christopher|6397
|
||||
James|5921
|
||||
Joseph|5711
|
||||
Brian|5059
|
||||
William|5047}
|
||||
Reference in New Issue
Block a user