Dandandan commented on code in PR #16433:
URL: https://github.com/apache/datafusion/pull/16433#discussion_r2186109216
##########
datafusion/physical-plan/src/topk/mod.rs:
##########
@@ -319,19 +342,75 @@ impl TopK {
/// (a > 2 OR (a = 2 AND b < 3))
/// ```
fn update_filter(&mut self) -> Result<()> {
- let Some(filter) = &self.filter else {
+ // If the heap doesn't have k elements yet, we can't create thresholds
+ let Some(max_row) = self.heap.max() else {
return Ok(());
};
- let Some(thresholds) = self.heap.get_threshold_values(&self.expr)?
else {
- return Ok(());
+
+ let new_threshold_row = &max_row.row;
+
+ // Extract filter expression reference before entering critical section
+ let filter_expr = Arc::clone(&self.filter.expr);
+
+ // Check if we need to update and do both threshold and filter update
atomically
+ {
+ let mut threshold_guard = self.filter.threshold_row.write();
+ if let Some(current_row) = threshold_guard.as_ref() {
+ match current_row.as_slice().cmp(new_threshold_row) {
+ Ordering::Greater => {
+ // new < current, so new threshold is more selective
Review Comment:
I guess we should try changing it to the global heap thing - write updates
to the shared/global heap and update the filter based on global heap.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]