@@ -314,6 +314,25 @@ pub enum Plan<T = mz_repr::Timestamp> {
314
314
} ,
315
315
}
316
316
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
+
317
336
impl < T : timely:: progress:: Timestamp > Plan < T > {
318
337
/// Replace the plan with another one
319
338
/// that has the collection in some additional forms.
@@ -379,6 +398,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
379
398
pub fn from_mir (
380
399
expr : & MirRelationExpr ,
381
400
arrangements : & mut BTreeMap < Id , AvailableCollections > ,
401
+ debug_info : LirDebugInfo < ' _ > ,
382
402
) -> Result < ( Self , AvailableCollections ) , ( ) > {
383
403
// This function is recursive and can overflow its stack, so grow it if
384
404
// needed. The growth here is unbounded. Our general solution for this problem
@@ -389,12 +409,13 @@ impl<T: timely::progress::Timestamp> Plan<T> {
389
409
// to allow the unbounded growth here. We are though somewhat protected by
390
410
// higher levels enforcing their own limits on stack depth (in the parser,
391
411
// 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 ) )
393
413
}
394
414
395
415
fn from_mir_inner (
396
416
expr : & MirRelationExpr ,
397
417
arrangements : & mut BTreeMap < Id , AvailableCollections > ,
418
+ debug_info : LirDebugInfo < ' _ > ,
398
419
) -> Result < ( Self , AvailableCollections ) , ( ) > {
399
420
// Extract a maximally large MapFilterProject from `expr`.
400
421
// We will then try and push this in to the resulting expression.
@@ -486,12 +507,12 @@ impl<T: timely::progress::Timestamp> Plan<T> {
486
507
487
508
// Plan the value using only the initial arrangements, but
488
509
// 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 ) ?;
490
511
let pre_existing = arrangements. insert ( Id :: Local ( * id) , v_keys) ;
491
512
assert ! ( pre_existing. is_none( ) ) ;
492
513
// Plan the body using initial and `value` arrangements,
493
514
// 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 ) ?;
495
516
arrangements. remove ( & Id :: Local ( * id) ) ;
496
517
// Return the plan, and any `body` arrangements.
497
518
(
@@ -504,7 +525,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
504
525
)
505
526
}
506
527
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 ) ?;
508
529
// This stage can absorb arbitrary MFP instances.
509
530
let mfp = mfp. take ( ) ;
510
531
let mut exprs = exprs. clone ( ) ;
@@ -549,7 +570,7 @@ impl<T: timely::progress::Timestamp> Plan<T> {
549
570
let mut input_keys = Vec :: new ( ) ;
550
571
let mut input_arities = Vec :: new ( ) ;
551
572
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 ) ?;
553
574
input_arities. push ( input. arity ( ) ) ;
554
575
plans. push ( plan) ;
555
576
input_keys. push ( keys) ;
@@ -599,7 +620,8 @@ impl<T: timely::progress::Timestamp> Plan<T> {
599
620
// are available. Print an error message, to increase the chances that
600
621
// the user will tell us about this.
601
622
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) ;
603
625
} else {
604
626
// It's fine and expected that linear joins don't have all their arrangements available up front,
605
627
// 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
631
653
} => {
632
654
let input_arity = input. arity ( ) ;
633
655
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 ) ?;
635
657
let ( input_key, permutation_and_new_arity) = if let Some ( (
636
658
input_key,
637
659
permutation,
@@ -674,7 +696,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
674
696
monotonic,
675
697
} => {
676
698
let arity = input. arity ( ) ;
677
- let ( input, keys) = Self :: from_mir ( input, arrangements) ?;
699
+ let ( input, keys) = Self :: from_mir ( input, arrangements, debug_info ) ?;
678
700
679
701
let top_k_plan = TopKPlan :: create_from (
680
702
group_key. clone ( ) ,
@@ -703,7 +725,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
703
725
}
704
726
MirRelationExpr :: Negate { input } => {
705
727
let arity = input. arity ( ) ;
706
- let ( input, keys) = Self :: from_mir ( input, arrangements) ?;
728
+ let ( input, keys) = Self :: from_mir ( input, arrangements, debug_info ) ?;
707
729
708
730
// We don't have an MFP here -- install an operator to permute the
709
731
// input, if necessary.
@@ -722,7 +744,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
722
744
}
723
745
MirRelationExpr :: Threshold { input } => {
724
746
let arity = input. arity ( ) ;
725
- let ( input, keys) = Self :: from_mir ( input, arrangements) ?;
747
+ let ( input, keys) = Self :: from_mir ( input, arrangements, debug_info ) ?;
726
748
// We don't have an MFP here -- install an operator to permute the
727
749
// input, if necessary.
728
750
let input = if !keys. raw {
@@ -759,10 +781,10 @@ This is not expected to cause incorrect results, but could indicate a performanc
759
781
MirRelationExpr :: Union { base, inputs } => {
760
782
let arity = base. arity ( ) ;
761
783
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 ) ?;
763
785
plans_keys. push ( ( plan, keys) ) ;
764
786
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 ) ?;
766
788
plans_keys. push ( ( plan, keys) ) ;
767
789
}
768
790
let plans = plans_keys
@@ -783,7 +805,7 @@ This is not expected to cause incorrect results, but could indicate a performanc
783
805
}
784
806
MirRelationExpr :: ArrangeBy { input, keys } => {
785
807
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 ) ?;
787
809
let keys = keys. iter ( ) . cloned ( ) . map ( |k| {
788
810
let ( permutation, thinning) = permutation_for_arrangement ( & k, arity) ;
789
811
( k, permutation, thinning)
@@ -932,7 +954,15 @@ This is not expected to cause incorrect results, but could indicate a performanc
932
954
// Build each object in order, registering the arrangements it forms.
933
955
let mut objects_to_build = Vec :: with_capacity ( desc. objects_to_build . len ( ) ) ;
934
956
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
+ ) ?;
936
966
arrangements. insert ( Id :: Global ( build. id ) , keys) ;
937
967
objects_to_build. push ( crate :: BuildDesc { id : build. id , plan } ) ;
938
968
}
0 commit comments