perf(sql): optimize count_distinct symbol function#3974
Merged
bluestreak01 merged 6 commits intomasterfrom Nov 20, 2023
Merged
Conversation
Includes the following optimizations: * Replaces CompactIntHashSet with BitSet in CountDistinctSymbolGroupByFunction. The former has a much more compact memory layout and faster operations. * Introduces early exit for SELECT count_distinct(sym_col) FROM my_table; queries. Exit condition is based on the symbol table size: as soon as it's reached, row iteration stops.
0320c1c to
98e3079
Compare
Member
|
@puzpuzpuz this is a very clever improvement 👍 how will it work with |
Contributor
Author
If the filtered symbol values are only a subset of the full symbol table, the early exit check will be no-op (full loop over the base cursor). If all symbol values are returned by the filter, the check will kick in and redundant iteration over the base cursor will stop. That's done only in the |
eugenels
reviewed
Nov 20, 2023
...ain/java/io/questdb/griffin/engine/functions/groupby/CountDistinctSymbolGroupByFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/questdb/griffin/engine/groupby/GroupByNotKeyedRecordCursorFactory.java
Outdated
Show resolved
Hide resolved
eugenels
previously approved these changes
Nov 20, 2023
Collaborator
[PR Coverage check]😍 pass : 68 / 71 (95.77%) file detail
|
eugenels
approved these changes
Nov 20, 2023
Contributor
Author
|
@eugenels thanks for the review! |
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.
Includes the following optimizations:
CompactIntHashSetwithBitSetinCountDistinctSymbolGroupByFunction. The former has a much more compact memory layout and faster operations.count_distinct()over symbol columns, e.g.SELECT count_distinct(sym_col) FROM my_table;. The exit condition is based on the symbol table sizes: as soon as they're reached, row iteration stops.