(dataflow: &mut DataflowDesc)
| 250 | fields(path.segment ="demand") |
| 251 | )] |
| 252 | fn optimize_dataflow_demand(dataflow: &mut DataflowDesc) -> Result<(), TransformError> { |
| 253 | // Maps id -> union of known columns demanded from the source/view with the |
| 254 | // corresponding id. |
| 255 | let mut demand = BTreeMap::new(); |
| 256 | |
| 257 | if dataflow.index_exports.is_empty() && dataflow.sink_exports.is_empty() { |
| 258 | // In the absence of any exports, just demand all columns from views |
| 259 | // that are not depended on by another view, which is currently the last |
| 260 | // object in `objects_to_build`. |
| 261 | |
| 262 | // A DataflowDesc without exports is currently created in the context of |
| 263 | // EXPLAIN outputs. This ensures that the output has all the columns of |
| 264 | // the original explainee. |
| 265 | if let Some(build_desc) = dataflow.objects_to_build.iter_mut().rev().next() { |
| 266 | demand |
| 267 | .entry(Id::Global(build_desc.id)) |
| 268 | .or_insert_with(BTreeSet::new) |
| 269 | .extend(0..build_desc.plan.as_inner_mut().arity()); |
| 270 | } |
| 271 | } else { |
| 272 | // Demand all columns of inputs to sinks. |
| 273 | for (_id, sink) in dataflow.sink_exports.iter() { |
| 274 | let input_id = sink.from; |
| 275 | demand |
| 276 | .entry(Id::Global(input_id)) |
| 277 | .or_insert_with(BTreeSet::new) |
| 278 | .extend(0..dataflow.arity_of(&input_id)); |
| 279 | } |
| 280 | |
| 281 | // Demand all columns of inputs to exported indexes. |
| 282 | for (_id, (desc, _typ)) in dataflow.index_exports.iter() { |
| 283 | let input_id = desc.on_id; |
| 284 | demand |
| 285 | .entry(Id::Global(input_id)) |
| 286 | .or_insert_with(BTreeSet::new) |
| 287 | .extend(0..dataflow.arity_of(&input_id)); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | optimize_dataflow_demand_inner( |
| 292 | dataflow |
| 293 | .objects_to_build |
| 294 | .iter_mut() |
| 295 | .rev() |
| 296 | .map(|build_desc| (Id::Global(build_desc.id), build_desc.plan.as_inner_mut())), |
| 297 | &mut demand, |
| 298 | )?; |
| 299 | |
| 300 | mz_repr::explain::trace_plan(dataflow); |
| 301 | |
| 302 | Ok(()) |
| 303 | } |
| 304 | |
| 305 | /// Pushes demand through views in `view_sequence` in order, removing |
| 306 | /// columns not demanded. |
no test coverage detected