-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Optimize count_distinct.size #5377
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
721a851
Optimize count_distinct.size
comphead 7e937ea
Optimize count_distinct.size for primitives only
comphead 6da6e28
Optimize count_distinct.size for primitives only
comphead 3e82039
Optimize count_distinct.size for primitives only
comphead 64dea1e
Optimize count_distinct.size for primitives only
comphead 669fb85
Optimize count_distinct.size. refactor
comphead 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,43 @@ impl DistinctCountAccumulator { | |
self.update(&row_values) | ||
}) | ||
} | ||
|
||
// calculating the size for fixed length values, taking first batch size * number of batches | ||
// This method is faster than .full_size(), however it is not suitable for variable length values like strings or complex types | ||
fn fixed_size(&self) -> usize { | ||
std::mem::size_of_val(self) | ||
+ (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity()) | ||
+ self | ||
.values | ||
.iter() | ||
.next() | ||
.map(|vals| { | ||
(ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0)) | ||
* self.values.capacity() | ||
}) | ||
.unwrap_or(0) | ||
} | ||
|
||
// calculates the size as accurate as possible, call to this method is expensive | ||
fn full_size(&self) -> usize { | ||
std::mem::size_of_val(self) | ||
+ (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity()) | ||
+ self | ||
.values | ||
.iter() | ||
.map(|vals| { | ||
ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0) | ||
}) | ||
.sum::<usize>() | ||
+ (std::mem::size_of::<DataType>() * self.state_data_types.capacity()) | ||
+ self | ||
.state_data_types | ||
.iter() | ||
.map(|dt| dt.size() - std::mem::size_of_val(dt)) | ||
.sum::<usize>() | ||
+ self.count_data_type.size() | ||
- std::mem::size_of_val(&self.count_data_type) | ||
} | ||
} | ||
|
||
impl Accumulator for DistinctCountAccumulator { | ||
|
@@ -216,23 +253,11 @@ impl Accumulator for DistinctCountAccumulator { | |
} | ||
|
||
fn size(&self) -> usize { | ||
std::mem::size_of_val(self) | ||
+ (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity()) | ||
+ self | ||
.values | ||
.iter() | ||
.map(|vals| { | ||
ScalarValue::size_of_vec(&vals.0) - std::mem::size_of_val(&vals.0) | ||
}) | ||
.sum::<usize>() | ||
+ (std::mem::size_of::<DataType>() * self.state_data_types.capacity()) | ||
+ self | ||
.state_data_types | ||
.iter() | ||
.map(|dt| dt.size() - std::mem::size_of_val(dt)) | ||
.sum::<usize>() | ||
+ self.count_data_type.size() | ||
- std::mem::size_of_val(&self.count_data_type) | ||
if self.count_data_type.is_primitive() { | ||
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. 👍 |
||
self.fixed_size() | ||
} else { | ||
self.full_size() | ||
} | ||
} | ||
} | ||
|
||
|
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.
👍 that is nice