Skip to content

Commit

Permalink
Reverse CTE order in EXPLAIN output
Browse files Browse the repository at this point in the history
  • Loading branch information
ggevay committed Jan 9, 2025
1 parent 3c610a2 commit 703db87
Show file tree
Hide file tree
Showing 111 changed files with 11,040 additions and 11,040 deletions.
16 changes: 8 additions & 8 deletions src/expr/src/explain/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,17 @@ impl MirRelationExpr {
self.fmt_analyses(f, ctx)?;
ctx.indented(|ctx| head.fmt_text(f, ctx))?;
} else {
write!(f, "{}Return", ctx.indent)?;
self.fmt_analyses(f, ctx)?;
ctx.indented(|ctx| head.fmt_text(f, ctx))?;
writeln!(f, "{}With", ctx.indent)?;
ctx.indented(|ctx| {
for (id, value) in bindings.iter().rev() {
for (id, value) in bindings.iter() {
writeln!(f, "{}cte {} =", ctx.indent, *id)?;
ctx.indented(|ctx| value.fmt_text(f, ctx))?;
}
Ok(())
})?;
write!(f, "{}Return", ctx.indent)?;
self.fmt_analyses(f, ctx)?;
ctx.indented(|ctx| head.fmt_text(f, ctx))?;
}
}
LetRec {
Expand All @@ -382,16 +382,13 @@ impl MirRelationExpr {
if ctx.config.linear_chains {
unreachable!(); // We exclude this case in `as_explain_single_plan`.
} else {
write!(f, "{}Return", ctx.indent)?;
self.fmt_analyses(f, ctx)?;
ctx.indented(|ctx| head.fmt_text(f, ctx))?;
write!(f, "{}With Mutually Recursive", ctx.indent)?;
if let Some(limit) = all_limits_same {
write!(f, " {}", limit)?;
}
writeln!(f)?;
ctx.indented(|ctx| {
for (id, value, limit) in bindings.iter().rev() {
for (id, value, limit) in bindings.iter() {
write!(f, "{}cte", ctx.indent)?;
if all_limits_same.is_none() {
if let Some(limit) = limit {
Expand All @@ -403,6 +400,9 @@ impl MirRelationExpr {
}
Ok(())
})?;
write!(f, "{}Return", ctx.indent)?;
self.fmt_analyses(f, ctx)?;
ctx.indented(|ctx| head.fmt_text(f, ctx))?;
}
}
Get {
Expand Down
258 changes: 129 additions & 129 deletions src/transform/tests/test_transforms/anf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ TopK order_by=[#1 asc nulls_last, #0 desc nulls_first] limit=3
Map (null::bigint)
Get t0
----
Return
Get l8
With
cte l8 =
TopK order_by=[#1 asc nulls_last, #0 desc nulls_first] limit=3
Get l7
cte l7 =
Reduce group_by=[#0] aggregates=[min(#1), max(#2)]
Get l6
cte l6 =
ArrangeBy keys=[[#1], [#2, #3]]
Get l5
cte l5 =
Threshold
Get l4
cte l4 =
Negate
Get l3
cte l3 =
Project (#2, #0, #1)
Get l2
cte l2 =
Filter (#0 > 0)
Get l1
cte l0 =
Get t0
cte l1 =
Map (null)
Get l0
cte l0 =
Get t0
cte l2 =
Filter (#0 > 0)
Get l1
cte l3 =
Project (#2, #0, #1)
Get l2
cte l4 =
Negate
Get l3
cte l5 =
Threshold
Get l4
cte l6 =
ArrangeBy keys=[[#1], [#2, #3]]
Get l5
cte l7 =
Reduce group_by=[#0] aggregates=[min(#1), max(#2)]
Get l6
cte l8 =
TopK order_by=[#1 asc nulls_last, #0 desc nulls_first] limit=3
Get l7
Return
Get l8

# Joins.
apply pipeline=anf
Expand All @@ -68,18 +68,18 @@ Join on=(#0 = #2 = #4)
Constant <empty> // { types: "(bigint, bigint)" }
Get t0
----
Return
Get l2
With
cte l0 =
Get t0
cte l1 =
Constant <empty>
cte l2 =
Join on=(#0 = #2 = #4)
Get l0
Get l1
Get l0
cte l1 =
Constant <empty>
cte l0 =
Get t0
Return
Get l2

# Union.
apply pipeline=anf
Expand All @@ -88,18 +88,18 @@ Union
Constant <empty> // { types: "(bigint, bigint)" }
Get t0
----
Return
Get l2
With
cte l0 =
Get t0
cte l1 =
Constant <empty>
cte l2 =
Union
Get l0
Get l1
Get l0
cte l1 =
Constant <empty>
cte l0 =
Get t0
Return
Get l2


## LetRec cases
Expand Down Expand Up @@ -154,76 +154,76 @@ With
Project (#0, #1)
Get t0
----
Return
Get l21
With
cte l0 =
Get t0
cte l1 =
Project (#0, #1)
Get l0
cte l2 =
Union
Get l1
Get l1
cte l21 =
Return
Return
Get l20
With
cte l20 =
Union
Get l17
Get l18
Get l19
cte l19 =
Filter (#1 > 7)
Get l11
cte l18 =
Filter (#1 > 7)
Get l15
cte l17 =
Filter (#1 > 7)
Get l16
cte l16 =
Get t0
With Mutually Recursive
cte l15 =
Get l14
cte l14 =
Distinct project=[#0, #1]
Get l13
cte l13 =
Union
Get l6
Get l12
Get l12
Get l8
Get l8
cte l12 =
cte l6 =
Filter (#1 > 7)
Get l2
cte l7 =
Filter (#1 > 7)
Get l11
cte l11 =
Get l10
cte l10 =
Distinct project=[#0, #1]
Get l9
cte l8 =
Filter (#1 > 7)
Get l15
cte l9 =
Union
Get l6
Get l7
Get l7
Get l8
Get l8
cte l8 =
Filter (#1 > 7)
Get l15
cte l7 =
cte l10 =
Distinct project=[#0, #1]
Get l9
cte l11 =
Get l10
cte l12 =
Filter (#1 > 7)
Get l11
cte l6 =
Filter (#1 > 7)
Get l2
cte l2 =
Union
Get l1
Get l1
cte l1 =
Project (#0, #1)
Get l0
cte l0 =
Get t0
cte l13 =
Union
Get l6
Get l12
Get l12
Get l8
Get l8
cte l14 =
Distinct project=[#0, #1]
Get l13
cte l15 =
Get l14
Return
With
cte l16 =
Get t0
cte l17 =
Filter (#1 > 7)
Get l16
cte l18 =
Filter (#1 > 7)
Get l15
cte l19 =
Filter (#1 > 7)
Get l11
cte l20 =
Union
Get l17
Get l18
Get l19
Return
Get l20
Return
Get l21

# From a failing test
# See https://github.com/MaterializeInc/materialize/pull/19287#issuecomment-1555923422.
Expand Down Expand Up @@ -251,48 +251,48 @@ With Mutually Recursive
Get t0
Get l1
----
Return
Get l15
With
cte l15 =
Return
Return
Get l14
With
cte l14 =
Project (#1)
Get l13
cte l13 =
Filter (#1 > 7)
Get l12
cte l12 =
Map ((#0 + #0))
Get l6
With Mutually Recursive
cte l11 =
Get l10
cte l10 =
cte l3 =
Get t0
cte l4 =
Project (#0)
Get l3
cte l5 =
Union
Get l4
Get l11
cte l6 =
Get l5
cte l7 =
Map ((#0 + #0))
Get l6
Get l9
Get l9
cte l9 =
Project (#1)
Get l8
cte l8 =
Filter (#1 > 7)
Get l7
cte l7 =
Map ((#0 + #0))
Get l6
cte l6 =
Get l5
cte l5 =
cte l9 =
Project (#1)
Get l8
cte l10 =
Union
Get l4
Get l11
cte l4 =
Project (#0)
Get l3
cte l3 =
Get t0
Get l6
Get l9
Get l9
cte l11 =
Get l10
Return
With
cte l12 =
Map ((#0 + #0))
Get l6
cte l13 =
Filter (#1 > 7)
Get l12
cte l14 =
Project (#1)
Get l13
Return
Get l14
Return
Get l15
Loading

0 comments on commit 703db87

Please sign in to comment.