Skip to content

Minor: do not extract heap threshold values if not updating filter #37

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

Merged
merged 1 commit into from
Aug 22, 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
12 changes: 6 additions & 6 deletions datafusion/physical-plan/src/topk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,6 @@ impl TopK {

let new_threshold_row = &max_row.row;

// Extract scalar values BEFORE acquiring lock to reduce critical section
let thresholds = match self.heap.get_threshold_values(&self.expr)? {
Some(t) => t,
None => return Ok(()),
};

// Fast path: check if the current value in topk is better than what is
// currently set in the filter with a read only lock
let needs_update = self
Expand All @@ -374,6 +368,12 @@ impl TopK {
return Ok(());
}

// Extract scalar values BEFORE acquiring lock to reduce critical section
let thresholds = match self.heap.get_threshold_values(&self.expr)? {
Some(t) => t,
None => return Ok(()),
Copy link
Author

Choose a reason for hiding this comment

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

this was an early return, but I was thinking that extracting the values can be delayed until after we decided if an update is needed

};

// Build the filter expression OUTSIDE any synchronization
let predicate = Self::build_filter_expression(&self.expr, thresholds)?;
let new_threshold = new_threshold_row.to_vec();
Expand Down
Loading