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

Function annotate_plan

src/transform/src/analysis.rs:1290–1399  ·  view source on GitHub ↗

Produce an [`AnnotatedPlan`] wrapping the given [`MirRelationExpr`] along with [`Analyses`] derived from the given context configuration.

(
        plan: &'a MirRelationExpr,
        context: &'a ExplainContext,
    )

Source from the content-addressed store, hash-verified

1288 /// Produce an [`AnnotatedPlan`] wrapping the given [`MirRelationExpr`] along
1289 /// with [`Analyses`] derived from the given context configuration.
1290 pub fn annotate_plan<'a>(
1291 plan: &'a MirRelationExpr,
1292 context: &'a ExplainContext,
1293 ) -> Result<AnnotatedPlan<'a, MirRelationExpr>, RecursionLimitError> {
1294 let mut annotations = BTreeMap::<&MirRelationExpr, Analyses>::default();
1295 let config = context.config;
1296
1297 // We want to annotate the plan with analyses in the following cases:
1298 // 1. An Analysis was explicitly requested in the ExplainConfig.
1299 // 2. Humanized expressions were requested in the ExplainConfig (in which
1300 // case we need to derive the ColumnNames Analysis).
1301 if config.requires_analyses() || config.humanized_exprs {
1302 // get the annotation keys
1303 let subtree_refs = plan.post_order_vec();
1304 // get the annotation values
1305 let builder = DerivedBuilder::from(context);
1306 let derived = builder.visit(plan);
1307
1308 if config.subtree_size {
1309 for (expr, subtree_size) in std::iter::zip(
1310 subtree_refs.iter(),
1311 &*derived.results::<super::SubtreeSize>(),
1312 ) {
1313 let analyses = annotations.entry(expr).or_default();
1314 analyses.subtree_size = Some(*subtree_size);
1315 }
1316 }
1317 if config.non_negative {
1318 for (expr, non_negative) in std::iter::zip(
1319 subtree_refs.iter(),
1320 &*derived.results::<super::NonNegative>(),
1321 ) {
1322 let analyses = annotations.entry(expr).or_default();
1323 analyses.non_negative = Some(*non_negative);
1324 }
1325 }
1326
1327 if config.arity {
1328 for (expr, arity) in
1329 std::iter::zip(subtree_refs.iter(), &*derived.results::<super::Arity>())
1330 {
1331 let analyses = annotations.entry(expr).or_default();
1332 analyses.arity = Some(*arity);
1333 }
1334 }
1335
1336 if config.types {
1337 for (expr, types) in std::iter::zip(
1338 subtree_refs.iter(),
1339 &*derived.results::<super::ReprRelationType>(),
1340 ) {
1341 let analyses = annotations.entry(expr).or_default();
1342 analyses.types = Some(types.clone());
1343 }
1344 }
1345
1346 if config.keys {
1347 for (expr, keys) in std::iter::zip(

Callers 4

as_explain_multi_planMethod · 0.85
handle_explainFunction · 0.85

Calls 11

requires_analysesMethod · 0.80
post_order_vecMethod · 0.80
visitMethod · 0.45
iterMethod · 0.45
entryMethod · 0.45
cloneMethod · 0.45
to_stringMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
humanizeMethod · 0.45
as_refMethod · 0.45

Tested by 2

handle_explainFunction · 0.68