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

Eliminate some typ() calls and an arity() call from MIR lowering #30879

Merged
merged 1 commit into from
Jan 6, 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
17 changes: 12 additions & 5 deletions src/compute-types/src/plan/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,20 @@ This is not expected to cause incorrect results, but could indicate a performanc
)
}
MirRelationExpr::Threshold { input } => {
let arity = input.arity();
let (plan, keys) = self.lower_mir_expr(input)?;
let arity = keys
.types
.as_ref()
.map(|types| types.len())
.unwrap_or_else(|| input.arity());
let (threshold_plan, required_arrangement) = ThresholdPlan::create_from(arity);
let mut types = keys.types.clone();
let plan = if !keys
.arranged
.iter()
.any(|(key, _, _)| key == &required_arrangement.0)
{
types = Some(input.typ().column_types);
types = Some(types.unwrap_or_else(|| input.typ().column_types));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do slightly better, sometimes avoiding the arity() call, by doing the following at the top of the function:

let (plan, keys) = self.lower_mir_expr(input)?;
let arity = types.as_ref().map(|types| types.len()).unwrap_or_else(|| input.arity());
let (threshold_plan, required_arrangement) = ThresholdPlan::create_from(arity);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed!

self.arrange_by(
plan,
AvailableCollections::new_arranged(
Expand Down Expand Up @@ -837,10 +841,13 @@ This is not expected to cause incorrect results, but could indicate a performanc
)
}
MirRelationExpr::ArrangeBy { input, keys } => {
let arity = input.arity();
let types = Some(input.typ().column_types);
let input_mir = input;
let (input, mut input_keys) = self.lower_mir_expr(input)?;
input_keys.types = types;
// Fill the `types` in `input_keys` if not already present.
let input_types = input_keys
.types
.get_or_insert_with(|| input_mir.typ().column_types);
let arity = input_types.len();

// Determine keys that are not present in `input_keys`.
let new_keys = keys
Expand Down
Loading