From 9ff2133ff2eb9853d572913a8def15bbbe08867b Mon Sep 17 00:00:00 2001 From: Piotr Rzysko Date: Fri, 12 Sep 2025 09:17:21 +0200 Subject: [PATCH] Rewrite window function expressions in the optimizer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, this is effectively a no-op because, at the optimization stage, window function expressions are in the form win_func(subquery_column1, subquery_column2, ...). Nevertheless, expressions are rewritten to maintain consistency with aggregates, which also hold cloned expressions from sources like result columns. This ensures future changes in the optimizer won’t break window function handling. --- core/translate/optimizer/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/translate/optimizer/mod.rs b/core/translate/optimizer/mod.rs index 74e458108..4bae8a1b1 100644 --- a/core/translate/optimizer/mod.rs +++ b/core/translate/optimizer/mod.rs @@ -578,6 +578,11 @@ fn rewrite_exprs_select(plan: &mut SelectPlan) -> Result<()> { for (expr, _) in plan.order_by.iter_mut() { rewrite_expr(expr, &mut param_count)?; } + if let Some(window) = &mut plan.window { + for func in window.functions.iter_mut() { + rewrite_expr(&mut func.original_expr, &mut param_count)?; + } + } Ok(()) }