Repository navigation
fix: preserve TopK dynamic filters across recursive CTE iterations - #26670
Merged
Merged
Conversation
jayzhan211
approved these changes
Oct 24, 2026
| .clone(); | ||
| // Our dynamic filter and execution metrics are the state we need to reset. | ||
| new_sort.filter = Some(new_sort.create_filter()); | ||
| let expr = new_sort.filter.as_ref().map(|filter| filter.read().expr()); |
Contributor
There was a problem hiding this comment.
nit: after the reset this is the same as the existing rebuild_filter_for_current_partitioning() helper, so it could reuse it:
- let expr = new_sort.filter.as_ref().map(|filter| filter.read().expr());
- if let Some(expr) = expr {
- expr.reset()?;
- new_sort.filter = Some(new_sort.create_filter_with_expr(expr));
+ if let Some(filter) = &new_sort.filter {
+ filter.read().expr().reset()?;
}
-
+ new_sort.rebuild_filter_for_current_partitioning();
new_sort.metrics_set = ExecutionPlanMetricsSet::new();
Contributor
Author
There was a problem hiding this comment.
My bad, missed the existing helper. reset_state() uses it now.
jayzhan211
approved these changes
Oct 25, 2026
| // Our dynamic filter and execution metrics are the state we need to reset. | ||
| new_sort.filter = Some(new_sort.create_filter()); | ||
| if let Some(filter) = &new_sort.filter { | ||
| filter.read().expr().reset()?; |
Contributor
There was a problem hiding this comment.
nit: #26669 makes DynamicFilterPhysicalExpr::reset() infallible, so this ? won't compile once both PRs are in. The two PRs touch different files, so git won't flag a conflict. Could you drop the ? in whichever of the two merges second (or rebase this one on #26669)?
- filter.read().expr().reset()?;
+ filter.read().expr().reset();
Contributor
There was a problem hiding this comment.
let me address this as well
Contributor
Author
There was a problem hiding this comment.
sorry didnt see it until now, Thanks
Contributor
|
Thanks @Kristofferjoha |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #26642.
Rationale for this change
TopK dynamic filters inside recursive CTEs stop updating the scan because
SortExec::reset_state()creates a new filter on each iteration, while the scan still references the original one. This prevents pruning during recursive queries.What changes are included in this PR?
DynamicFilterPhysicalExpr.cte.slt.Depends on #26056 for
DynamicFilterPhysicalExpr::reset(). It hasn't been merged yet, but it has been approved, so I based this change on its implementation.What is the testing strategy for this PR?
The new
cte.sltcase checks that the recursive query returns 1–4 and that the Parquet scan outputs 30 rows instead of 300, pruning 27 row groups across three iterations.Are there any user-facing changes?
No.