Pushes demand through views in `view_sequence` in order, removing columns not demanded. This method is made public for the sake of testing. TODO: make this private once we allow multiple exports per dataflow.
(
view_sequence: I,
demand: &mut BTreeMap<Id, BTreeSet<usize>>,
)
| 308 | /// This method is made public for the sake of testing. |
| 309 | /// TODO: make this private once we allow multiple exports per dataflow. |
| 310 | pub fn optimize_dataflow_demand_inner<'a, I>( |
| 311 | view_sequence: I, |
| 312 | demand: &mut BTreeMap<Id, BTreeSet<usize>>, |
| 313 | ) -> Result<(), TransformError> |
| 314 | where |
| 315 | I: Iterator<Item = (Id, &'a mut MirRelationExpr)>, |
| 316 | { |
| 317 | // Maps id -> The projection that was pushed down on the view with the |
| 318 | // corresponding id. |
| 319 | let mut applied_projection = BTreeMap::new(); |
| 320 | // Collect the mutable references to views after pushing projection down |
| 321 | // in order to run cleanup actions on them in a second loop. |
| 322 | let mut view_refs = Vec::new(); |
| 323 | let projection_pushdown = crate::movement::ProjectionPushdown::default(); |
| 324 | for (id, view) in view_sequence { |
| 325 | if let Some(columns) = demand.get(&id) { |
| 326 | let projection_pushed_down = columns.iter().map(|c| *c).collect(); |
| 327 | // Push down the projection consisting of the entries of `columns` |
| 328 | // in increasing order. |
| 329 | projection_pushdown.action(view, &projection_pushed_down, demand)?; |
| 330 | let new_type = view.typ(); |
| 331 | applied_projection.insert(id, (projection_pushed_down, new_type)); |
| 332 | } |
| 333 | view_refs.push(view); |
| 334 | } |
| 335 | |
| 336 | for view in view_refs { |
| 337 | // Update `Get` nodes to reflect any columns that have been projected away. |
| 338 | projection_pushdown.update_projection_around_get(view, &applied_projection); |
| 339 | } |
| 340 | |
| 341 | Ok(()) |
| 342 | } |
| 343 | |
| 344 | /// Pushes predicate to dataflow inputs. |
| 345 | #[mz_ore::instrument( |