-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Minor: add with_estimated_selectivity
to Precision
#8177
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,15 +200,12 @@ impl ExecutionPlan for FilterExec { | |
// assume filter selects 20% of rows if we cannot do anything smarter | ||
// tracking issue for making this configurable: | ||
// https://github.com/apache/arrow-datafusion/issues/8133 | ||
let selectivity = 0.2_f32; | ||
let mut stats = input_stats.into_inexact(); | ||
if let Precision::Inexact(n) = stats.num_rows { | ||
stats.num_rows = Precision::Inexact((selectivity * n as f32) as usize); | ||
} | ||
if let Precision::Inexact(n) = stats.total_byte_size { | ||
stats.total_byte_size = | ||
Precision::Inexact((selectivity * n as f32) as usize); | ||
} | ||
let selectivity = 0.2_f64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly this code from @andygrove in #8126 is different to the way the selectivity is implemented below -- it uses This PR makes sure these two paths are consistent which I think is an improvement |
||
let mut stats = input_stats.clone().into_inexact(); | ||
stats.num_rows = stats.num_rows.with_estimated_selectivity(selectivity); | ||
stats.total_byte_size = stats | ||
.total_byte_size | ||
.with_estimated_selectivity(selectivity); | ||
return Ok(stats); | ||
} | ||
|
||
|
@@ -222,14 +219,8 @@ impl ExecutionPlan for FilterExec { | |
|
||
// Estimate (inexact) selectivity of predicate | ||
let selectivity = analysis_ctx.selectivity.unwrap_or(1.0); | ||
let num_rows = match num_rows.get_value() { | ||
Some(nr) => Precision::Inexact((*nr as f64 * selectivity).ceil() as usize), | ||
None => Precision::Absent, | ||
}; | ||
let total_byte_size = match total_byte_size.get_value() { | ||
Some(tbs) => Precision::Inexact((*tbs as f64 * selectivity).ceil() as usize), | ||
None => Precision::Absent, | ||
}; | ||
let num_rows = num_rows.with_estimated_selectivity(selectivity); | ||
let total_byte_size = total_byte_size.with_estimated_selectivity(selectivity); | ||
|
||
let column_statistics = collect_new_statistics( | ||
&input_stats.column_statistics, | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use ceil in this case rather than
round
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Inexact(0) triggers some decisions at somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think there were several cases where DataFusion was (incorrectly) optimizing away scans based on
Inexact(0)
-- I tried to capture some of what is going on in the #8227 ticket if you are interestedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, specifically in this PR I used
ceil()
because that is what the existing code did in the older codepath.