Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optimizer] reduce .typ() and .arity() chatter in VOJ #30943

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/sql/src/plan/lowering/variadic_left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ pub(crate) fn attempt_left_join_magic(
) -> Result<Option<MirRelationExpr>, PlanError> {
use mz_expr::LocalId;

tracing::debug!(
inputs = rights.len() + 1,
outer_arity = get_outer.arity(),
"attempt_left_join_magic"
);

let inc_metrics = |case: &str| {
if let Some(metrics) = context.metrics {
metrics.inc_outer_join_lowering(case);
}
};

let oa = get_outer.arity();
tracing::debug!(
inputs = rights.len() + 1,
outer_arity = oa,
"attempt_left_join_magic"
);

if oa > 0 {
// Bail out in correlated contexts for now. Even though the code below
// supports them, we want to test this code path more thoroughly before
Expand All @@ -77,14 +77,20 @@ pub(crate) fn attempt_left_join_magic(
let left = left
.clone()
.applied_to(id_gen, get_outer.clone(), col_map, cte_map, context)?;
let lt = left.typ().column_types.into_iter().skip(oa).collect_vec();
let full_left_typ = left.typ();
let lt = full_left_typ
.column_types
.iter()
.skip(oa)
.cloned()
.collect_vec();
let la = lt.len();

// Create a new let binding to use as input.
// We may use these relations multiple times to extract augmenting values.
let id = LocalId::new(id_gen.allocate_id());
// The join body that we will iteratively develop.
let mut body = MirRelationExpr::local_get(id, left.typ());
let mut body = MirRelationExpr::local_get(id, full_left_typ);
bindings.push((id, body.clone(), left));
bound_to.extend((0..la).map(|_| 1));
arities.push(la);
Expand Down Expand Up @@ -112,10 +118,16 @@ pub(crate) fn attempt_left_join_magic(
.clone()
.map(vec![HirScalarExpr::literal_true()]) // add a bit to mark "real" rows.
.applied_to(id_gen, get_outer.clone(), &right_col_map, cte_map, context)?;
let rt = right.typ().column_types.into_iter().skip(oa).collect_vec();
let full_right_typ = right.typ();
let rt = full_right_typ
.column_types
.iter()
.skip(oa)
.cloned()
.collect_vec();
let ra = rt.len() - 1; // don't count the new column

let mut right_type = right.typ();
let mut right_type = full_right_typ;
// Create a binding for `right`, unadulterated.
let id = LocalId::new(id_gen.allocate_id());
let get_right = MirRelationExpr::local_get(id, right_type.clone());
Expand Down Expand Up @@ -152,7 +164,7 @@ pub(crate) fn attempt_left_join_magic(

// if `on` added any new columns, .. no clue what to do.
// Return with failure, to avoid any confusion.
if product.typ().column_types.len() > oa + ba + ra + 1 {
if product.arity() > oa + ba + ra + 1 {
tracing::debug!(case = 3, index, "attempt_left_join_magic");
inc_metrics("voj_3");
return Ok(None);
Expand Down Expand Up @@ -225,7 +237,7 @@ pub(crate) fn attempt_left_join_magic(
MirRelationExpr::Constant {
rows: Ok(vec![(
mz_repr::Row::pack(
std::iter::repeat(mz_repr::Datum::Null).take(get_left.arity()),
std::iter::repeat(mz_repr::Datum::Null).take(left_typ.arity()),
),
1,
)]),
Expand Down
Loading