MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / fuse_window_functions

Function fuse_window_functions

src/sql/src/plan/transform_hir.rs:407–774  ·  view source on GitHub ↗

# Aims and scope The aim here is to amortize the overhead of the MIR window function pattern (see `window_func_applied_to`) by fusing groups of window function calls such that each group can be performed by one instance of the window function MIR pattern. For now, we fuse only value window function calls and window aggregations. (We probably won't need to fuse scalar window functions for a long

(
    root: &mut HirRelationExpr,
    _context: &crate::plan::lowering::Context,
)

Source from the content-addressed store, hash-verified

405/// column references in the other direction, i.e., references in other expressions that refer to
406/// columns in the group.)
407pub fn fuse_window_functions(
408 root: &mut HirRelationExpr,
409 _context: &crate::plan::lowering::Context,
410) -> Result<(), RecursionLimitError> {
411 /// Those options of a window function call that are relevant for fusion.
412 #[derive(PartialEq, Eq)]
413 enum WindowFuncCallOptions {
414 Value(ValueWindowFuncCallOptions),
415 Agg(AggregateWindowFuncCallOptions),
416 }
417 #[derive(PartialEq, Eq)]
418 struct ValueWindowFuncCallOptions {
419 partition_by: Vec<HirScalarExpr>,
420 outer_order_by: Vec<HirScalarExpr>,
421 inner_order_by: Vec<ColumnOrder>,
422 window_frame: WindowFrame,
423 ignore_nulls: bool,
424 }
425 #[derive(PartialEq, Eq)]
426 struct AggregateWindowFuncCallOptions {
427 partition_by: Vec<HirScalarExpr>,
428 outer_order_by: Vec<HirScalarExpr>,
429 inner_order_by: Vec<ColumnOrder>,
430 window_frame: WindowFrame,
431 distinct: bool,
432 }
433
434 /// Helper function to extract the above options.
435 fn extract_options(call: &HirScalarExpr) -> WindowFuncCallOptions {
436 match call {
437 HirScalarExpr::Windowing(
438 WindowExpr {
439 func:
440 WindowExprType::Value(ValueWindowExpr {
441 order_by: inner_order_by,
442 window_frame,
443 ignore_nulls,
444 func: _,
445 args: _,
446 }),
447 partition_by,
448 order_by: outer_order_by,
449 },
450 _name,
451 ) => WindowFuncCallOptions::Value(ValueWindowFuncCallOptions {
452 partition_by: partition_by.clone(),
453 outer_order_by: outer_order_by.clone(),
454 inner_order_by: inner_order_by.clone(),
455 window_frame: window_frame.clone(),
456 ignore_nulls: ignore_nulls.clone(),
457 }),
458 HirScalarExpr::Windowing(
459 WindowExpr {
460 func:
461 WindowExprType::Aggregate(AggregateWindowExpr {
462 aggregate_expr:
463 AggregateExpr {
464 distinct,

Callers 1

lowerMethod · 0.85

Calls 15

extract_optionsFunction · 0.85
try_visit_mut_postMethod · 0.80
enumerateMethod · 0.80
allMethod · 0.80
expectMethod · 0.80
fuseMethod · 0.80
remapMethod · 0.80
arityMethod · 0.45
lenMethod · 0.45
mapMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected