(
id_gen: &mut mz_ore::id_gen::IdGen,
col_map: &ColumnMap,
cte_map: &mut CteMap,
inner: &mut MirRelationExpr,
subquery_map: &Option<&BTreeMap<HirScalarExpr, usi
| 1365 | } |
| 1366 | |
| 1367 | fn window_func_applied_to<F>( |
| 1368 | id_gen: &mut mz_ore::id_gen::IdGen, |
| 1369 | col_map: &ColumnMap, |
| 1370 | cte_map: &mut CteMap, |
| 1371 | inner: &mut MirRelationExpr, |
| 1372 | subquery_map: &Option<&BTreeMap<HirScalarExpr, usize>>, |
| 1373 | partition_by: Vec<HirScalarExpr>, |
| 1374 | order_by: Vec<HirScalarExpr>, |
| 1375 | mir_aggr_func: AggregateFunc, |
| 1376 | lower_args: F, |
| 1377 | context: &Context, |
| 1378 | ) -> Result<MirScalarExpr, PlanError> |
| 1379 | where |
| 1380 | F: FnOnce( |
| 1381 | &mut mz_ore::id_gen::IdGen, |
| 1382 | &ColumnMap, |
| 1383 | &mut CteMap, |
| 1384 | &mut MirRelationExpr, |
| 1385 | &Option<&BTreeMap<HirScalarExpr, usize>>, |
| 1386 | Vec<MirScalarExpr>, |
| 1387 | MirScalarExpr, |
| 1388 | SqlScalarType, |
| 1389 | ) -> Result<(MirScalarExpr, SqlColumnType), PlanError>, |
| 1390 | { |
| 1391 | // Example MIRs for a window function (specifically, a window aggregation): |
| 1392 | // |
| 1393 | // CREATE TABLE t7(x INT, y INT); |
| 1394 | // |
| 1395 | // explain decorrelated plan for select sum(x*y) over (partition by x+y order by x-y, x/y) from t7; |
| 1396 | // |
| 1397 | // Decorrelated Plan |
| 1398 | // Project (#3) |
| 1399 | // Map (#2) |
| 1400 | // Project (#3..=#5) |
| 1401 | // Map (record_get[0](record_get[1](#2)), record_get[1](record_get[1](#2)), record_get[0](#2)) |
| 1402 | // FlatMap unnest_list(#1) |
| 1403 | // Reduce group_by=[#2] aggregates=[window_agg[sum order_by=[#0 asc nulls_last, #1 asc nulls_last]](row(row(row(#0, #1), (#0 * #1)), (#0 - #1), (#0 / #1)))] |
| 1404 | // Map ((#0 + #1)) |
| 1405 | // CrossJoin |
| 1406 | // Constant |
| 1407 | // - () |
| 1408 | // Get materialize.public.t7 |
| 1409 | // |
| 1410 | // The same query after optimizations: |
| 1411 | // |
| 1412 | // explain select sum(x*y) over (partition by x+y order by x-y, x/y) from t7; |
| 1413 | // |
| 1414 | // Optimized Plan |
| 1415 | // Explained Query: |
| 1416 | // Project (#2) |
| 1417 | // Map (record_get[0](#1)) |
| 1418 | // FlatMap unnest_list(#0) |
| 1419 | // Project (#1) |
| 1420 | // Reduce group_by=[(#0 + #1)] aggregates=[window_agg[sum order_by=[#0 asc nulls_last, #1 asc nulls_last]](row(row(row(#0, #1), (#0 * #1)), (#0 - #1), (#0 / #1)))] |
| 1421 | // ReadStorage materialize.public.t7 |
| 1422 | // |
| 1423 | // The `row(row(row(...), ...), ...)` stuff means the following: |
| 1424 | // `row(row(row(<original row>), <arguments to window function>), <order by values>...)` |
nothing calls this directly
no test coverage detected