1use itertools::Itertools;
34use proptest_derive::Arbitrary;
35use serde::{Deserialize, Serialize};
36use std::borrow::Cow;
37use std::collections::{BTreeMap, BTreeSet};
38use std::fmt;
39use std::fmt::{Display, Formatter};
40
41use mz_ore::stack::RecursionLimitError;
42use mz_ore::str::{Indent, bracketed, separated};
43
44use crate::explain::dot::{DisplayDot, dot_string};
45use crate::explain::json::{DisplayJson, json_string};
46use crate::explain::text::{DisplayText, text_string};
47use crate::optimize::OptimizerFeatureOverrides;
48use crate::{GlobalId, ReprColumnType, ReprScalarType, SqlColumnType, SqlScalarType};
49
50pub mod dot;
51pub mod json;
52pub mod text;
53#[cfg(feature = "tracing")]
54pub mod tracing;
55
56#[cfg(feature = "tracing")]
57pub use crate::explain::tracing::trace_plan;
58
59#[derive(Debug, Clone, Copy, Eq, PartialEq)]
61pub enum ExplainFormat {
62 Text,
63 Json,
64 Dot,
65}
66
67impl fmt::Display for ExplainFormat {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 match self {
70 ExplainFormat::Text => f.write_str("TEXT"),
71 ExplainFormat::Json => f.write_str("JSON"),
72 ExplainFormat::Dot => f.write_str("DOT"),
73 }
74 }
75}
76
77#[allow(missing_debug_implementations)]
81pub enum UnsupportedFormat {}
82
83#[derive(Debug)]
86pub enum ExplainError {
87 UnsupportedFormat(ExplainFormat),
88 FormatError(fmt::Error),
89 AnyhowError(anyhow::Error),
90 RecursionLimitError(RecursionLimitError),
91 SerdeJsonError(serde_json::Error),
92 LinearChainsPlusRecursive,
93 UnknownError(String),
94}
95
96impl fmt::Display for ExplainError {
97 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
98 write!(f, "error while rendering explain output: ")?;
99 match self {
100 ExplainError::UnsupportedFormat(format) => {
101 write!(f, "{} format is not supported", format)
102 }
103 ExplainError::FormatError(error) => {
104 write!(f, "{}", error)
105 }
106 ExplainError::AnyhowError(error) => {
107 write!(f, "{}", error)
108 }
109 ExplainError::RecursionLimitError(error) => {
110 write!(f, "{}", error)
111 }
112 ExplainError::SerdeJsonError(error) => {
113 write!(f, "{}", error)
114 }
115 ExplainError::LinearChainsPlusRecursive => {
116 write!(
117 f,
118 "The linear_chains option is not supported with WITH MUTUALLY RECURSIVE."
119 )
120 }
121 ExplainError::UnknownError(error) => {
122 write!(f, "{}", error)
123 }
124 }
125 }
126}
127
128impl From<fmt::Error> for ExplainError {
129 fn from(error: fmt::Error) -> Self {
130 ExplainError::FormatError(error)
131 }
132}
133
134impl From<anyhow::Error> for ExplainError {
135 fn from(error: anyhow::Error) -> Self {
136 ExplainError::AnyhowError(error)
137 }
138}
139
140impl From<RecursionLimitError> for ExplainError {
141 fn from(error: RecursionLimitError) -> Self {
142 ExplainError::RecursionLimitError(error)
143 }
144}
145
146impl From<serde_json::Error> for ExplainError {
147 fn from(error: serde_json::Error) -> Self {
148 ExplainError::SerdeJsonError(error)
149 }
150}
151
152#[derive(Clone, Debug)]
154pub struct ExplainConfig {
155 pub subtree_size: bool,
159 pub arity: bool,
161 pub types: bool,
163 pub keys: bool,
165 pub non_negative: bool,
167 pub cardinality: bool,
169 pub column_names: bool,
171 pub equivalences: bool,
173 pub join_impls: bool,
179 pub humanized_exprs: bool,
181 pub linear_chains: bool,
183 pub no_fast_path: bool,
186 pub no_notices: bool,
188 pub node_ids: bool,
190 pub raw_plans: bool,
192 pub raw_syntax: bool,
194 pub verbose_syntax: bool,
196 pub redacted: bool,
198 pub timing: bool,
200 pub filter_pushdown: bool,
202
203 pub features: OptimizerFeatureOverrides,
205}
206
207impl Default for ExplainConfig {
208 fn default() -> Self {
209 Self {
210 redacted: !mz_ore::assert::soft_assertions_enabled(),
212 arity: false,
213 cardinality: false,
214 column_names: false,
215 filter_pushdown: false,
216 humanized_exprs: false,
217 join_impls: true,
218 keys: false,
219 linear_chains: false,
220 no_fast_path: true,
221 no_notices: false,
222 node_ids: false,
223 non_negative: false,
224 raw_plans: true,
225 raw_syntax: false,
226 verbose_syntax: false,
227 subtree_size: false,
228 timing: false,
229 types: false,
230 equivalences: false,
231 features: Default::default(),
232 }
233 }
234}
235
236impl ExplainConfig {
237 pub fn requires_analyses(&self) -> bool {
238 self.subtree_size
239 || self.non_negative
240 || self.arity
241 || self.types
242 || self.keys
243 || self.cardinality
244 || self.column_names
245 || self.equivalences
246 }
247}
248
249#[derive(Clone, Debug)]
251pub enum Explainee {
252 MaterializedView(GlobalId),
254 Index(GlobalId),
256 Dataflow(GlobalId),
260 Select,
263}
264
265pub trait Explain<'a>: 'a {
271 type Context;
274
275 type Text: DisplayText;
278
279 type Json: DisplayJson;
282
283 type Dot: DisplayDot;
286
287 fn explain(
302 &'a mut self,
303 format: &'a ExplainFormat,
304 context: &'a Self::Context,
305 ) -> Result<String, ExplainError> {
306 match format {
307 ExplainFormat::Text => self.explain_text(context).map(|e| text_string(&e)),
308 ExplainFormat::Json => self.explain_json(context).map(|e| json_string(&e)),
309 ExplainFormat::Dot => self.explain_dot(context).map(|e| dot_string(&e)),
310 }
311 }
312
313 #[allow(unused_variables)]
325 fn explain_text(&'a mut self, context: &'a Self::Context) -> Result<Self::Text, ExplainError> {
326 Err(ExplainError::UnsupportedFormat(ExplainFormat::Text))
327 }
328
329 #[allow(unused_variables)]
341 fn explain_json(&'a mut self, context: &'a Self::Context) -> Result<Self::Json, ExplainError> {
342 Err(ExplainError::UnsupportedFormat(ExplainFormat::Json))
343 }
344
345 #[allow(unused_variables)]
357 fn explain_dot(&'a mut self, context: &'a Self::Context) -> Result<Self::Dot, ExplainError> {
358 Err(ExplainError::UnsupportedFormat(ExplainFormat::Dot))
359 }
360}
361
362#[derive(Debug)]
366pub struct RenderingContext<'a> {
367 pub indent: Indent,
368 pub humanizer: &'a dyn ExprHumanizer,
369}
370
371impl<'a> RenderingContext<'a> {
372 pub fn new(indent: Indent, humanizer: &'a dyn ExprHumanizer) -> RenderingContext<'a> {
373 RenderingContext { indent, humanizer }
374 }
375}
376
377impl<'a> AsMut<Indent> for RenderingContext<'a> {
378 fn as_mut(&mut self) -> &mut Indent {
379 &mut self.indent
380 }
381}
382
383impl<'a> AsRef<&'a dyn ExprHumanizer> for RenderingContext<'a> {
384 fn as_ref(&self) -> &&'a dyn ExprHumanizer {
385 &self.humanizer
386 }
387}
388
389#[allow(missing_debug_implementations)]
390pub struct PlanRenderingContext<'a, T> {
391 pub indent: Indent,
392 pub humanizer: &'a dyn ExprHumanizer,
393 pub annotations: BTreeMap<&'a T, Analyses>,
394 pub config: &'a ExplainConfig,
395 pub ambiguous_ids: BTreeSet<GlobalId>,
397}
398
399impl<'a, T> PlanRenderingContext<'a, T> {
400 pub fn new(
401 indent: Indent,
402 humanizer: &'a dyn ExprHumanizer,
403 annotations: BTreeMap<&'a T, Analyses>,
404 config: &'a ExplainConfig,
405 ambiguous_ids: BTreeSet<GlobalId>,
406 ) -> PlanRenderingContext<'a, T> {
407 PlanRenderingContext {
408 indent,
409 humanizer,
410 annotations,
411 config,
412 ambiguous_ids,
413 }
414 }
415
416 pub fn humanize_id_maybe_unqualified(&self, id: GlobalId) -> Option<String> {
418 if self.ambiguous_ids.contains(&id) {
419 self.humanizer.humanize_id(id)
420 } else {
421 self.humanizer.humanize_id_unqualified(id)
422 }
423 }
424}
425
426impl<'a, T> AsMut<Indent> for PlanRenderingContext<'a, T> {
427 fn as_mut(&mut self) -> &mut Indent {
428 &mut self.indent
429 }
430}
431
432impl<'a, T> AsRef<&'a dyn ExprHumanizer> for PlanRenderingContext<'a, T> {
433 fn as_ref(&self) -> &&'a dyn ExprHumanizer {
434 &self.humanizer
435 }
436}
437
438pub trait ExprHumanizer: fmt::Debug + Sync {
443 fn humanize_id(&self, id: GlobalId) -> Option<String>;
446
447 fn humanize_id_unqualified(&self, id: GlobalId) -> Option<String>;
449
450 fn humanize_id_parts(&self, id: GlobalId) -> Option<Vec<String>>;
453
454 fn humanize_scalar_type(&self, ty: &SqlScalarType, postgres_compat: bool) -> String;
459
460 fn humanize_scalar_type_repr(&self, typ: &ReprScalarType, postgres_compat: bool) -> String {
463 self.humanize_scalar_type(&SqlScalarType::from_repr(typ), postgres_compat)
464 }
465
466 fn humanize_column_type(&self, typ: &SqlColumnType, postgres_compat: bool) -> String {
471 format!(
472 "{}{}",
473 self.humanize_scalar_type(&typ.scalar_type, postgres_compat),
474 if typ.nullable { "?" } else { "" }
475 )
476 }
477
478 fn humanize_column_type_repr(&self, typ: &ReprColumnType, postgres_compat: bool) -> String {
481 self.humanize_column_type(&SqlColumnType::from_repr(typ), postgres_compat)
482 }
483
484 fn column_names_for_id(&self, id: GlobalId) -> Option<Vec<String>>;
486
487 fn humanize_column(&self, id: GlobalId, column: usize) -> Option<String>;
489
490 fn id_exists(&self, id: GlobalId) -> bool;
492}
493
494#[derive(Debug)]
497pub struct ExprHumanizerExt<'a> {
498 items: BTreeMap<GlobalId, TransientItem>,
501 inner: &'a dyn ExprHumanizer,
504}
505
506impl<'a> ExprHumanizerExt<'a> {
507 pub fn new(items: BTreeMap<GlobalId, TransientItem>, inner: &'a dyn ExprHumanizer) -> Self {
508 Self { items, inner }
509 }
510}
511
512impl<'a> ExprHumanizer for ExprHumanizerExt<'a> {
513 fn humanize_id(&self, id: GlobalId) -> Option<String> {
514 match self.items.get(&id) {
515 Some(item) => item
516 .humanized_id_parts
517 .as_ref()
518 .map(|parts| parts.join(".")),
519 None => self.inner.humanize_id(id),
520 }
521 }
522
523 fn humanize_id_unqualified(&self, id: GlobalId) -> Option<String> {
524 match self.items.get(&id) {
525 Some(item) => item
526 .humanized_id_parts
527 .as_ref()
528 .and_then(|parts| parts.last().cloned()),
529 None => self.inner.humanize_id_unqualified(id),
530 }
531 }
532
533 fn humanize_id_parts(&self, id: GlobalId) -> Option<Vec<String>> {
534 match self.items.get(&id) {
535 Some(item) => item.humanized_id_parts.clone(),
536 None => self.inner.humanize_id_parts(id),
537 }
538 }
539
540 fn humanize_scalar_type(&self, ty: &SqlScalarType, postgres_compat: bool) -> String {
541 self.inner.humanize_scalar_type(ty, postgres_compat)
542 }
543
544 fn column_names_for_id(&self, id: GlobalId) -> Option<Vec<String>> {
545 match self.items.get(&id) {
546 Some(item) => item.column_names.clone(),
547 None => self.inner.column_names_for_id(id),
548 }
549 }
550
551 fn humanize_column(&self, id: GlobalId, column: usize) -> Option<String> {
552 match self.items.get(&id) {
553 Some(item) => match &item.column_names {
554 Some(column_names) => Some(column_names[column].clone()),
555 None => None,
556 },
557 None => self.inner.humanize_column(id, column),
558 }
559 }
560
561 fn id_exists(&self, id: GlobalId) -> bool {
562 self.items.contains_key(&id) || self.inner.id_exists(id)
563 }
564}
565
566#[derive(Debug)]
570pub struct TransientItem {
571 humanized_id_parts: Option<Vec<String>>,
572 column_names: Option<Vec<String>>,
573}
574
575impl TransientItem {
576 pub fn new(humanized_id_parts: Option<Vec<String>>, column_names: Option<Vec<String>>) -> Self {
577 Self {
578 humanized_id_parts,
579 column_names,
580 }
581 }
582}
583
584#[derive(Debug)]
590pub struct DummyHumanizer;
591
592impl ExprHumanizer for DummyHumanizer {
593 fn humanize_id(&self, _: GlobalId) -> Option<String> {
594 None
597 }
598
599 fn humanize_id_unqualified(&self, _id: GlobalId) -> Option<String> {
600 None
601 }
602
603 fn humanize_id_parts(&self, _id: GlobalId) -> Option<Vec<String>> {
604 None
605 }
606
607 fn humanize_scalar_type(&self, ty: &SqlScalarType, _postgres_compat: bool) -> String {
608 format!("{:?}", ty)
610 }
611
612 fn column_names_for_id(&self, _id: GlobalId) -> Option<Vec<String>> {
613 None
614 }
615
616 fn humanize_column(&self, _id: GlobalId, _column: usize) -> Option<String> {
617 None
618 }
619
620 fn id_exists(&self, _id: GlobalId) -> bool {
621 false
622 }
623}
624
625#[derive(Debug)]
627pub struct Indices<'a>(pub &'a [usize]);
628
629#[derive(Debug)]
634pub struct CompactScalarSeq<'a, T: ScalarOps>(pub &'a [T]); #[derive(Debug)]
641pub struct CompactScalars<T, I>(pub I)
642where
643 T: ScalarOps,
644 I: Iterator<Item = T> + Clone;
645
646pub trait ScalarOps {
647 fn match_col_ref(&self) -> Option<usize>;
648
649 fn references(&self, col_ref: usize) -> bool;
650}
651
652#[allow(missing_debug_implementations)]
655pub struct AnnotatedPlan<'a, T> {
656 pub plan: &'a T,
657 pub annotations: BTreeMap<&'a T, Analyses>,
658}
659
660#[derive(Clone, Default, Debug)]
662pub struct Analyses {
663 pub non_negative: Option<bool>,
664 pub subtree_size: Option<usize>,
665 pub arity: Option<usize>,
666 pub types: Option<Option<Vec<SqlColumnType>>>,
667 pub keys: Option<Vec<Vec<usize>>>,
668 pub cardinality: Option<String>,
669 pub column_names: Option<Vec<String>>,
670 pub equivalences: Option<String>,
671}
672
673#[derive(Debug, Clone)]
674pub struct HumanizedAnalyses<'a> {
675 analyses: &'a Analyses,
676 humanizer: &'a dyn ExprHumanizer,
677 config: &'a ExplainConfig,
678}
679
680impl<'a> HumanizedAnalyses<'a> {
681 pub fn new<T>(analyses: &'a Analyses, ctx: &PlanRenderingContext<'a, T>) -> Self {
682 Self {
683 analyses,
684 humanizer: ctx.humanizer,
685 config: ctx.config,
686 }
687 }
688}
689
690impl<'a> Display for HumanizedAnalyses<'a> {
691 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
696 let mut builder = f.debug_struct("//");
697
698 if self.config.subtree_size {
699 let subtree_size = self.analyses.subtree_size.expect("subtree_size");
700 builder.field("subtree_size", &subtree_size);
701 }
702
703 if self.config.non_negative {
704 let non_negative = self.analyses.non_negative.expect("non_negative");
705 builder.field("non_negative", &non_negative);
706 }
707
708 if self.config.arity {
709 let arity = self.analyses.arity.expect("arity");
710 builder.field("arity", &arity);
711 }
712
713 if self.config.types {
714 let types = match self.analyses.types.as_ref().expect("types") {
715 Some(types) => {
716 let types = types
717 .into_iter()
718 .map(|c| self.humanizer.humanize_column_type(c, false))
719 .collect::<Vec<_>>();
720
721 bracketed("(", ")", separated(", ", types)).to_string()
722 }
723 None => "(<error>)".to_string(),
724 };
725 builder.field("types", &types);
726 }
727
728 if self.config.keys {
729 let keys = self
730 .analyses
731 .keys
732 .as_ref()
733 .expect("keys")
734 .into_iter()
735 .map(|key| bracketed("[", "]", separated(", ", key)).to_string());
736 let keys = bracketed("(", ")", separated(", ", keys)).to_string();
737 builder.field("keys", &keys);
738 }
739
740 if self.config.cardinality {
741 let cardinality = self.analyses.cardinality.as_ref().expect("cardinality");
742 builder.field("cardinality", cardinality);
743 }
744
745 if self.config.column_names {
746 let column_names = self.analyses.column_names.as_ref().expect("column_names");
747 let column_names = column_names.into_iter().enumerate().map(|(i, c)| {
748 if c.is_empty() {
749 Cow::Owned(format!("#{i}"))
750 } else {
751 Cow::Borrowed(c)
752 }
753 });
754 let column_names = bracketed("(", ")", separated(", ", column_names)).to_string();
755 builder.field("column_names", &column_names);
756 }
757
758 if self.config.equivalences {
759 let equivs = self.analyses.equivalences.as_ref().expect("equivalences");
760 builder.field("equivs", equivs);
761 }
762
763 builder.finish()
764 }
765}
766
767#[derive(Clone, Debug, Default)]
776pub struct UsedIndexes(BTreeSet<(GlobalId, Vec<IndexUsageType>)>);
777
778impl UsedIndexes {
779 pub fn new(values: BTreeSet<(GlobalId, Vec<IndexUsageType>)>) -> UsedIndexes {
780 UsedIndexes(values)
781 }
782
783 pub fn is_empty(&self) -> bool {
784 self.0.is_empty()
785 }
786
787 pub fn ambiguous_ids(&self, humanizer: &dyn ExprHumanizer) -> BTreeSet<GlobalId> {
789 let humanized = self
790 .0
791 .iter()
792 .flat_map(|(id, _)| humanizer.humanize_id_unqualified(*id).map(|hum| (hum, *id)));
793
794 let mut by_humanization = BTreeMap::<String, BTreeSet<GlobalId>>::new();
795 for (hum, id) in humanized {
796 by_humanization.entry(hum).or_default().insert(id);
797 }
798
799 by_humanization
800 .values()
801 .filter(|ids| ids.len() > 1)
802 .flatten()
803 .cloned()
804 .collect()
805 }
806}
807
808#[derive(
809 Debug,
810 Clone,
811 Arbitrary,
812 Serialize,
813 Deserialize,
814 Eq,
815 PartialEq,
816 Ord,
817 PartialOrd,
818 Hash
819)]
820pub enum IndexUsageType {
821 FullScan,
823 DifferentialJoin,
825 DeltaJoin(DeltaJoinIndexUsageType),
827 Lookup(GlobalId),
832 PlanRootNoArrangement,
838 SinkExport,
841 IndexExport,
844 FastPathLimit,
849 DanglingArrangeBy,
855 Unknown,
858}
859
860#[derive(
864 Debug,
865 Clone,
866 Arbitrary,
867 Serialize,
868 Deserialize,
869 Eq,
870 PartialEq,
871 Ord,
872 PartialOrd,
873 Hash
874)]
875pub enum DeltaJoinIndexUsageType {
876 Unknown,
877 Lookup,
878 FirstInputFullScan,
879}
880
881impl std::fmt::Display for IndexUsageType {
882 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
883 write!(
884 f,
885 "{}",
886 match self {
887 IndexUsageType::FullScan => "*** full scan ***",
888 IndexUsageType::Lookup(_idx_id) => "lookup",
889 IndexUsageType::DifferentialJoin => "differential join",
890 IndexUsageType::DeltaJoin(DeltaJoinIndexUsageType::FirstInputFullScan) =>
891 "delta join 1st input (full scan)",
892 IndexUsageType::DeltaJoin(DeltaJoinIndexUsageType::Lookup) => "delta join lookup",
899 IndexUsageType::DeltaJoin(DeltaJoinIndexUsageType::Unknown) =>
900 "*** INTERNAL ERROR (unknown delta join usage) ***",
901 IndexUsageType::PlanRootNoArrangement => "plan root (no new arrangement)",
902 IndexUsageType::SinkExport => "sink export",
903 IndexUsageType::IndexExport => "index export",
904 IndexUsageType::FastPathLimit => "fast path limit",
905 IndexUsageType::DanglingArrangeBy => "*** INTERNAL ERROR (dangling ArrangeBy) ***",
906 IndexUsageType::Unknown => "*** INTERNAL ERROR (unknown usage) ***",
907 }
908 )
909 }
910}
911
912impl IndexUsageType {
913 pub fn display_vec<'a, I>(usage_types: I) -> impl Display + Sized + 'a
914 where
915 I: IntoIterator<Item = &'a IndexUsageType>,
916 {
917 separated(", ", usage_types.into_iter().sorted().dedup())
918 }
919}
920
921#[cfg(test)]
922mod tests {
923 use mz_ore::assert_ok;
924
925 use super::*;
926
927 struct Environment {
928 name: String,
929 }
930
931 impl Default for Environment {
932 fn default() -> Self {
933 Environment {
934 name: "test env".to_string(),
935 }
936 }
937 }
938
939 struct Frontiers<T> {
940 since: T,
941 upper: T,
942 }
943
944 impl<T> Frontiers<T> {
945 fn new(since: T, upper: T) -> Self {
946 Self { since, upper }
947 }
948 }
949
950 struct ExplainContext<'a> {
951 env: &'a mut Environment,
952 config: &'a ExplainConfig,
953 frontiers: Frontiers<u64>,
954 }
955
956 struct TestExpr {
958 lhs: i32,
959 rhs: i32,
960 }
961
962 struct TestExplanation<'a> {
963 expr: &'a TestExpr,
964 context: &'a ExplainContext<'a>,
965 }
966
967 impl<'a> DisplayText for TestExplanation<'a> {
968 fn fmt_text(&self, f: &mut fmt::Formatter<'_>, _ctx: &mut ()) -> fmt::Result {
969 let lhs = &self.expr.lhs;
970 let rhs = &self.expr.rhs;
971 writeln!(f, "expr = {lhs} + {rhs}")?;
972
973 if self.context.config.timing {
974 let since = &self.context.frontiers.since;
975 let upper = &self.context.frontiers.upper;
976 writeln!(f, "at t ∊ [{since}, {upper})")?;
977 }
978
979 let name = &self.context.env.name;
980 writeln!(f, "env = {name}")?;
981
982 Ok(())
983 }
984 }
985
986 impl<'a> Explain<'a> for TestExpr {
987 type Context = ExplainContext<'a>;
988 type Text = TestExplanation<'a>;
989 type Json = UnsupportedFormat;
990 type Dot = UnsupportedFormat;
991
992 fn explain_text(
993 &'a mut self,
994 context: &'a Self::Context,
995 ) -> Result<Self::Text, ExplainError> {
996 Ok(TestExplanation {
997 expr: self,
998 context,
999 })
1000 }
1001 }
1002
1003 fn do_explain(
1004 env: &mut Environment,
1005 frontiers: Frontiers<u64>,
1006 ) -> Result<String, ExplainError> {
1007 let mut expr = TestExpr { lhs: 1, rhs: 2 };
1008
1009 let format = ExplainFormat::Text;
1010 let config = &ExplainConfig {
1011 redacted: false,
1012 arity: false,
1013 cardinality: false,
1014 column_names: false,
1015 filter_pushdown: false,
1016 humanized_exprs: false,
1017 join_impls: false,
1018 keys: false,
1019 linear_chains: false,
1020 no_fast_path: false,
1021 no_notices: false,
1022 node_ids: false,
1023 non_negative: false,
1024 raw_plans: false,
1025 raw_syntax: false,
1026 verbose_syntax: true,
1027 subtree_size: false,
1028 equivalences: false,
1029 timing: true,
1030 types: false,
1031 features: Default::default(),
1032 };
1033 let context = ExplainContext {
1034 env,
1035 config,
1036 frontiers,
1037 };
1038
1039 expr.explain(&format, &context)
1040 }
1041
1042 #[mz_ore::test]
1043 fn test_mutable_context() {
1044 let mut env = Environment::default();
1045 let frontiers = Frontiers::<u64>::new(3, 7);
1046
1047 let act = do_explain(&mut env, frontiers);
1048 let exp = "expr = 1 + 2\nat t ∊ [3, 7)\nenv = test env\n".to_string();
1049
1050 assert_ok!(act);
1051 assert_eq!(act.unwrap(), exp);
1052 }
1053}