From ce8b2722cf025019b13db429019825819056ae18 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Sat, 17 May 2025 17:28:29 +0300 Subject: [PATCH] optimizer: fix incorrect logic in group_by_contains_all --- core/translate/optimizer/order.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/translate/optimizer/order.rs b/core/translate/optimizer/order.rs index b6ff1ade3..61c722069 100644 --- a/core/translate/optimizer/order.rs +++ b/core/translate/optimizer/order.rs @@ -97,10 +97,11 @@ pub fn compute_order_target( // however in this case we must take the ASC/DESC from ORDER BY into account. (Some(order_by), Some(group_by)) => { // Does the group by contain all expressions in the order by? - let group_by_contains_all = group_by.exprs.iter().all(|expr| { - order_by + let group_by_contains_all = order_by.iter().all(|(expr, _)| { + group_by + .exprs .iter() - .any(|(order_by_expr, _)| exprs_are_equivalent(expr, order_by_expr)) + .any(|group_by_expr| exprs_are_equivalent(expr, group_by_expr)) }); // If not, let's try to target an ordering that matches the group by -- we don't care about ASC/DESC if !group_by_contains_all {