Skip to content

Commit

Permalink
Add Differential join's start_keys to EXPLAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
ggevay committed Nov 29, 2022
1 parent 6ba0f5d commit 08088a4
Show file tree
Hide file tree
Showing 26 changed files with 269 additions and 252 deletions.
41 changes: 29 additions & 12 deletions src/adapter/src/explain_new/mir/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,35 @@ impl<'a> Displayable<'a, MirRelationExpr> {
None => format!("%{}", pos),
}
};
let join_order = |head_idx: usize,
let join_key_to_string = |key: &Vec<MirScalarExpr>| -> String {
if key.is_empty() {
"×".to_owned()
} else {
separated_text(", ", key.iter().map(Displayable::from)).to_string()
}
};
let join_order = |start_idx: usize,
start_key: &Option<Vec<MirScalarExpr>>,
tail: &Vec<(
usize,
Vec<MirScalarExpr>,
Option<JoinInputCharacteristics>,
)>|
-> String {
format!(
"{} » {}",
input_name(head_idx),
"{}{} » {}",
input_name(start_idx),
match start_key {
None => "".to_owned(),
Some(key) => format!("[{}]", join_key_to_string(key)),
},
separated(
" » ",
tail.iter().map(|(pos, key, characteristics)| {
format!(
"{}[{}]{}",
input_name(*pos),
if key.is_empty() {
"×".to_owned()
} else {
separated_text(", ", key.iter().map(Displayable::from))
.to_string()
},
join_key_to_string(key),
characteristics
.as_ref()
.map(|c| c.explain())
Expand All @@ -287,12 +294,17 @@ impl<'a> Displayable<'a, MirRelationExpr> {
};
ctx.indented(|ctx| {
match implementation {
JoinImplementation::Differential((head_idx, _head_key), tail) => {
JoinImplementation::Differential((start_idx, start_key), tail) => {
soft_assert!(inputs.len() == tail.len() + 1);

writeln!(f, "{}implementation", ctx.indent)?;
ctx.indented(|ctx| {
writeln!(f, "{}{}", ctx.indent, join_order(*head_idx, tail))
writeln!(
f,
"{}{}",
ctx.indent,
join_order(*start_idx, start_key, tail)
)
})?;
}
JoinImplementation::DeltaQuery(half_join_chains) => {
Expand All @@ -301,7 +313,12 @@ impl<'a> Displayable<'a, MirRelationExpr> {
writeln!(f, "{}implementation", ctx.indent)?;
ctx.indented(|ctx| {
for (pos, chain) in half_join_chains.iter().enumerate() {
writeln!(f, "{}{}", ctx.indent, join_order(pos, chain))?;
writeln!(
f,
"{}{}",
ctx.indent,
join_order(pos, &None, chain)
)?;
}
Ok(())
})?;
Expand Down
12 changes: 6 additions & 6 deletions test/sqllogictest/autogenerated/all_parts_essential.slt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Explained Query:
Filter ((#4 = 24) OR ((#3 = 6) AND (#4 <= 4) AND (#4 >= 3))) // { arity: 25 }
Join on=(#0 = #16) type=differential // { arity: 25 }
implementation
%1:orders » %0:lineitem[#0]KAeif
%1:orders[#0] » %0:lineitem[#0]KAeif
ArrangeBy keys=[[#0]] // { arity: 16 }
Get materialize.public.lineitem // { arity: 16 }
ArrangeBy keys=[[#0]] // { arity: 9 }
Expand Down Expand Up @@ -414,7 +414,7 @@ Explained Query:
Project (#0) // { arity: 1 }
Join on=(#1 = #2) type=differential // { arity: 3 }
implementation
%0:l1 » %1[#0]UKAif
%0:l1[#1] » %1[#0]UKAif
ArrangeBy keys=[[#1]] // { arity: 2 }
Project (#4, #11) // { arity: 2 }
Get l1 // { arity: 16 }
Expand All @@ -435,7 +435,7 @@ Explained Query:
Project (#0..=#4) // { arity: 5 }
Join on=(#2 = #5) type=differential // { arity: 6 }
implementation
%1:orders » %0:lineitem[#2]KA
%1:orders[#1] » %0:lineitem[#2]KA
ArrangeBy keys=[[#2]] // { arity: 4 }
Project (#0, #4, #11, #12) // { arity: 4 }
Get materialize.public.lineitem // { arity: 16 }
Expand Down Expand Up @@ -480,7 +480,7 @@ Explained Query:
Filter (#12 <= #5) AND ((#1 = 7) OR (#1 = 33) OR ((#1 = 17) AND (#13 <= "x") AND (#13 >= "s"))) // { arity: 14 }
Join on=(#0 = #2) type=differential // { arity: 14 }
implementation
%2:customer » %0:lineitem[×]Aef » %1:orders[#0]KAef
%2:customer[×] » %0:lineitem[×]Aef » %1:orders[#0]KAef
ArrangeBy keys=[[]] // { arity: 2 }
Project (#0, #4) // { arity: 2 }
Filter ((#4 = 7) OR (#4 = 17) OR (#4 = 33)) // { arity: 16 }
Expand Down Expand Up @@ -589,7 +589,7 @@ Explained Query:
Filter (#1 < #6) AND (#16 > #5) AND (#16 >= #0) // { arity: 19 }
Join on=(#3 = #11) type=differential // { arity: 19 }
implementation
%2:customer » %1:orders[#1]KA » %0:lineitem[×]Af
%2:customer[#0] » %1:orders[#1]KA » %0:lineitem[×]Af
ArrangeBy keys=[[]] // { arity: 2 }
Project (#5, #10) // { arity: 2 }
Filter (#3 != 4) // { arity: 16 }
Expand Down Expand Up @@ -692,7 +692,7 @@ Explained Query:
Filter (#10 <= 1994-03-17) AND (#0 >= 53) AND (#5 < #19) AND (#26 < #19) // { arity: 27 }
Join on=(#0 = #16) type=differential // { arity: 27 }
implementation
%1:orders » %0:lineitem[#0]KAiiiiif » %2:customer[×]Aiiiiif
%1:orders[#0] » %0:lineitem[#0]KAiiiiif » %2:customer[×]Aiiiiif
ArrangeBy keys=[[#0]] // { arity: 16 }
Get materialize.public.lineitem // { arity: 16 }
ArrangeBy keys=[[#0]] // { arity: 9 }
Expand Down
Loading

0 comments on commit 08088a4

Please sign in to comment.