forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitee1b30f
committed
Add template for adaptive radix tree
This implements a radix tree data structure based on the design in"The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases"by Viktor Leis, Alfons Kemper, and ThomasNeumann, 2013. The maintechnique that makes it adaptive is using several different node types,each with a different capacity of elements, and a different algorithmfor accessing them. The nodes start small and grow/shrink as needed.The main advantage over hash tables is efficient sorted iteration andbetter memory locality when successive keys are lexicographicallyclose together. The implementation currently assumes 64-bit integerkeys, and traversing the tree is in general slower than a linearprobing hash table, so this is not a general-purpose associative array.The paper describes two other techniques not implemented here,namely "path compression" and "lazy expansion". These can furtherreduce memory usage and speed up traversal, but the former would addsignificant complexity and the latter requires storing the full keywith the value. We do trivially compress the path when leading bytesof the key are zeros, however.For value storage, we use "combined pointer/value slots", asrecommended in the paper. Values of size equal or smaller than the theplatform's pointer type are stored in the array of child pointers inthe last level node, while larger values are each stored in a separateallocation. This is for now fixed at compile time, but it would befairly trivial to allow determining at runtime how variable-lengthvalues are stored.One innovation in our implementation compared to the ART paper isdecoupling the notion of node "size class" from "kind". The sizeclasses within a given node kind have the same underlying type, buta variable capacity for children, so we can introduce additional nodesizes with little additional code.To enable different use cases to specialize for different value typesand for shared/local memory, we use macro-templatized code generationin the same manner as simplehash.h and sort_template.h.Future commits will use this infrastructure for storing TIDs.Patch by Masahiko Sawada and John Naylor, but a substantial amount ofcredit is due to Andres Freund, whose proof-of-concept was a valuablesource of coding idioms and awareness of performance pitfalls, andwho reviewed earlier versions.Discussion:https://postgr.es/m/CAD21AoAfOZvmfR0j8VmZorZjL7RhTiQdVttNuC4W-Shdc2a-AA%40mail.gmail.com1 parent65db0cf commitee1b30f
File tree
14 files changed
+3620
-0
lines changed- src
- backend/utils/mmgr
- include
- lib
- utils
- test/modules
- test_radixtree
- expected
- sql
- tools/pgindent
14 files changed
+3620
-0
lines changedLines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1035 | 1035 |
| |
1036 | 1036 |
| |
1037 | 1037 |
| |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
1038 | 1051 |
| |
1039 | 1052 |
| |
1040 | 1053 |
| |
|
0 commit comments
Comments
(0)