Skip to content

Commit 4855737

Browse files
umanwizardAndi Wang
authored andcommitted
Add debug name to LIR planning (MaterializeInc#11721)
1 parent 59ac394 commit 4855737

File tree

1 file changed

+44
-14
lines changed
  • src/dataflow-types/src/plan

1 file changed

+44
-14
lines changed

src/dataflow-types/src/plan/mod.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,25 @@ pub enum Plan<T = mz_repr::Timestamp> {
314314
},
315315
}
316316

317+
/// Various bits of state to print along with error messages during LIR planning,
318+
/// to aid debugging.
319+
#[derive(Copy, Clone, Debug)]
320+
pub struct LirDebugInfo<'a> {
321+
debug_name: &'a str,
322+
id: GlobalId,
323+
dataflow_uuid: uuid::Uuid,
324+
}
325+
326+
impl<'a> std::fmt::Display for LirDebugInfo<'a> {
327+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
328+
write!(
329+
f,
330+
"Debug name: {}; id: {}; dataflow UUID: {}",
331+
self.debug_name, self.id, self.dataflow_uuid
332+
)
333+
}
334+
}
335+
317336
impl<T: timely::progress::Timestamp> Plan<T> {
318337
/// Replace the plan with another one
319338
/// that has the collection in some additional forms.
@@ -379,6 +398,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
379398
pub fn from_mir(
380399
expr: &MirRelationExpr,
381400
arrangements: &mut BTreeMap<Id, AvailableCollections>,
401+
debug_info: LirDebugInfo<'_>,
382402
) -> Result<(Self, AvailableCollections), ()> {
383403
// This function is recursive and can overflow its stack, so grow it if
384404
// needed. The growth here is unbounded. Our general solution for this problem
@@ -389,12 +409,13 @@ impl<T: timely::progress::Timestamp> Plan<T> {
389409
// to allow the unbounded growth here. We are though somewhat protected by
390410
// higher levels enforcing their own limits on stack depth (in the parser,
391411
// transformer/desugarer, and planner).
392-
mz_ore::stack::maybe_grow(|| Plan::from_mir_inner(expr, arrangements))
412+
mz_ore::stack::maybe_grow(|| Plan::from_mir_inner(expr, arrangements, debug_info))
393413
}
394414

395415
fn from_mir_inner(
396416
expr: &MirRelationExpr,
397417
arrangements: &mut BTreeMap<Id, AvailableCollections>,
418+
debug_info: LirDebugInfo<'_>,
398419
) -> Result<(Self, AvailableCollections), ()> {
399420
// Extract a maximally large MapFilterProject from `expr`.
400421
// We will then try and push this in to the resulting expression.
@@ -486,12 +507,12 @@ impl<T: timely::progress::Timestamp> Plan<T> {
486507

487508
// Plan the value using only the initial arrangements, but
488509
// introduce any resulting arrangements bound to `id`.
489-
let (value, v_keys) = Plan::from_mir(value, arrangements)?;
510+
let (value, v_keys) = Plan::from_mir(value, arrangements, debug_info)?;
490511
let pre_existing = arrangements.insert(Id::Local(*id), v_keys);
491512
assert!(pre_existing.is_none());
492513
// Plan the body using initial and `value` arrangements,
493514
// and then remove reference to the value arrangements.
494-
let (body, b_keys) = Plan::from_mir(body, arrangements)?;
515+
let (body, b_keys) = Plan::from_mir(body, arrangements, debug_info)?;
495516
arrangements.remove(&Id::Local(*id));
496517
// Return the plan, and any `body` arrangements.
497518
(
@@ -504,7 +525,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
504525
)
505526
}
506527
MirRelationExpr::FlatMap { input, func, exprs } => {
507-
let (input, keys) = Plan::from_mir(input, arrangements)?;
528+
let (input, keys) = Plan::from_mir(input, arrangements, debug_info)?;
508529
// This stage can absorb arbitrary MFP instances.
509530
let mfp = mfp.take();
510531
let mut exprs = exprs.clone();
@@ -549,7 +570,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
549570
let mut input_keys = Vec::new();
550571
let mut input_arities = Vec::new();
551572
for input in inputs.iter() {
552-
let (plan, keys) = Plan::from_mir(input, arrangements)?;
573+
let (plan, keys) = Plan::from_mir(input, arrangements, debug_info)?;
553574
input_arities.push(input.arity());
554575
plans.push(plan);
555576
input_keys.push(keys);
@@ -599,7 +620,8 @@ impl<T: timely::progress::Timestamp> Plan<T> {
599620
// are available. Print an error message, to increase the chances that
600621
// the user will tell us about this.
601622
soft_panic_or_log!("Arrangements depended on by delta join alarmingly absent: {:?}
602-
This is not expected to cause incorrect results, but could indicate a performance issue in Materialize.", missing);
623+
Dataflow info: {}
624+
This is not expected to cause incorrect results, but could indicate a performance issue in Materialize.", missing, debug_info);
603625
} else {
604626
// It's fine and expected that linear joins don't have all their arrangements available up front,
605627
// so no need to print an error here.
@@ -631,7 +653,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
631653
} => {
632654
let input_arity = input.arity();
633655
let output_arity = group_key.len() + aggregates.len();
634-
let (input, keys) = Self::from_mir(input, arrangements)?;
656+
let (input, keys) = Self::from_mir(input, arrangements, debug_info)?;
635657
let (input_key, permutation_and_new_arity) = if let Some((
636658
input_key,
637659
permutation,
@@ -674,7 +696,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
674696
monotonic,
675697
} => {
676698
let arity = input.arity();
677-
let (input, keys) = Self::from_mir(input, arrangements)?;
699+
let (input, keys) = Self::from_mir(input, arrangements, debug_info)?;
678700

679701
let top_k_plan = TopKPlan::create_from(
680702
group_key.clone(),
@@ -703,7 +725,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
703725
}
704726
MirRelationExpr::Negate { input } => {
705727
let arity = input.arity();
706-
let (input, keys) = Self::from_mir(input, arrangements)?;
728+
let (input, keys) = Self::from_mir(input, arrangements, debug_info)?;
707729

708730
// We don't have an MFP here -- install an operator to permute the
709731
// input, if necessary.
@@ -722,7 +744,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
722744
}
723745
MirRelationExpr::Threshold { input } => {
724746
let arity = input.arity();
725-
let (input, keys) = Self::from_mir(input, arrangements)?;
747+
let (input, keys) = Self::from_mir(input, arrangements, debug_info)?;
726748
// We don't have an MFP here -- install an operator to permute the
727749
// input, if necessary.
728750
let input = if !keys.raw {
@@ -759,10 +781,10 @@ This is not expected to cause incorrect results, but could indicate a performanc
759781
MirRelationExpr::Union { base, inputs } => {
760782
let arity = base.arity();
761783
let mut plans_keys = Vec::with_capacity(1 + inputs.len());
762-
let (plan, keys) = Self::from_mir(base, arrangements)?;
784+
let (plan, keys) = Self::from_mir(base, arrangements, debug_info)?;
763785
plans_keys.push((plan, keys));
764786
for input in inputs.iter() {
765-
let (plan, keys) = Self::from_mir(input, arrangements)?;
787+
let (plan, keys) = Self::from_mir(input, arrangements, debug_info)?;
766788
plans_keys.push((plan, keys));
767789
}
768790
let plans = plans_keys
@@ -783,7 +805,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
783805
}
784806
MirRelationExpr::ArrangeBy { input, keys } => {
785807
let arity = input.arity();
786-
let (input, mut input_keys) = Self::from_mir(input, arrangements)?;
808+
let (input, mut input_keys) = Self::from_mir(input, arrangements, debug_info)?;
787809
let keys = keys.iter().cloned().map(|k| {
788810
let (permutation, thinning) = permutation_for_arrangement(&k, arity);
789811
(k, permutation, thinning)
@@ -932,7 +954,15 @@ This is not expected to cause incorrect results, but could indicate a performanc
932954
// Build each object in order, registering the arrangements it forms.
933955
let mut objects_to_build = Vec::with_capacity(desc.objects_to_build.len());
934956
for build in desc.objects_to_build.into_iter() {
935-
let (plan, keys) = Self::from_mir(&build.plan, &mut arrangements)?;
957+
let (plan, keys) = Self::from_mir(
958+
&build.plan,
959+
&mut arrangements,
960+
LirDebugInfo {
961+
debug_name: &desc.debug_name,
962+
id: build.id,
963+
dataflow_uuid: desc.id,
964+
},
965+
)?;
936966
arrangements.insert(Id::Global(build.id), keys);
937967
objects_to_build.push(crate::BuildDesc { id: build.id, plan });
938968
}

0 commit comments

Comments
 (0)