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

Function optimize_dataflow_demand

src/transform/src/dataflow.rs:252–303  ·  view source on GitHub ↗
(dataflow: &mut DataflowDesc)

Source from the content-addressed store, hash-verified

250 fields(path.segment ="demand")
251)]
252fn 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.

Callers 1

optimize_dataflowFunction · 0.85

Calls 11

trace_planFunction · 0.85
as_inner_mutMethod · 0.80
arity_ofMethod · 0.80
is_emptyMethod · 0.45
nextMethod · 0.45
extendMethod · 0.45
entryMethod · 0.45
arityMethod · 0.45
iterMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected