-
Notifications
You must be signed in to change notification settings - Fork 2.5k
General ART improvements and memory pressure reduction #8437
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
Conversation
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
…e to make tests run faster
# Conflicts: # src/execution/index/art/node.cpp
# Conflicts: # src/storage/checkpoint_manager.cpp # src/storage/wal_replay.cpp
2 tasks
Mytherin
reviewed
Aug 2, 2023
pdet
suggested changes
Aug 3, 2023
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.
Tania, great PR! Thanks for it!
I just had some small code nips, and a couple questions about one of the tests!
src/include/duckdb/execution/operator/schema/physical_create_index.hpp
Outdated
Show resolved
Hide resolved
src/include/duckdb/execution/operator/schema/physical_create_index.hpp
Outdated
Show resolved
Hide resolved
|
Thanks! LGTM |
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.
This PR combines several changes to the ART and mainly focuses on reducing its memory pressure during index creation (
CREATE INDEX). Combining these changes significantly improves ART creation performance and its memory footprint.Memory pressure reduction
Disable sorting for
VARCHARand compound keysBefore this PR, we always add a sorting operator to the pipeline preceding the index creation operator. Especially for
VARCHARkeys and compound keys, this sorting operation significantly blew up the memory.Now, we check the key types during plan creation. If we detect a
VARCHARor compound key type, we adjust the pipeline accordingly, i.e., we do not add that sorting operator.This change has implications for the execution of the create index operator, which previously expected its incoming data to be sorted. We now have to distinguish between the sorted and not sorted cases and only execute the old (faster)
Sinkimplementation on sorted data. This is still desirable since the regression in performance is negligible, and the memory pressure decreases significantly. For not sorted data, we now insert the keys key-at-a-time into the thread-local ART of a sink.ARTs can now share their memory
Each thread has its local ART. We build a chunk-sized ART with an efficient construction strategy that does not require iterating all keys for every incoming chunk of sorted data. We then merge that chunk-sized ART into the thread-local ART. This merging step is very efficient since all operations are on sorted data.
Before this PR, the chunk-sized ART would allocate its own memory, which would then get appended to the thread-local ART's memory. This significantly blows up the memory, as we preallocate blocks of 256KB.
This PR allows ARTs to share their memory. Consequently, the thread-local ART can now share its memory with the chunk-sized ART, decreasing memory pressure.
Performance improvements
Tree structures such as the ART make it tempting to use recursion for simplicity. For specific scenarios, such as many duplicate keys, or very long prefixes, using recursion for some functions can become problematic. The recursion depth incurs significant overhead in function calls.
Therefore, this PR changes some function implementations from recursive to iterative ones (for
LeafandPrefix).Free,Vacuum,Deserialize,SerializeBenchmarks
I also want to show some benchmark numbers, to highlight the positive effect of the reduction in memory pressure on performance. All the benchmarks can be found in
benchmark/micro/index/create/.VARCHAR, 7.2M distinct, 8GB memory limitINT64, 2.5M distinctVARCHARVARCHARINT, approx. 1M distinctINT, approx. 100 distinctOther improvements
VARCHARindex creation with a memory limit to detect regression on the memory consumptionDELETEandINSERToperationsVacuumto theFinalizestep of the index creation operation. This is now possible because the thread-local ARTs share their memory.This PR also closes the following issues.