pgsql: Add template for adaptive radix tree

Поиск
Список
Период
Сортировка
От John Naylor
Тема pgsql: Add template for adaptive radix tree
Дата
Msg-id E1ri6dQ-002VQl-2Y@gemulon.postgresql.org
обсуждение исходный текст
Ответы Re: pgsql: Add template for adaptive radix tree  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: pgsql: Add template for adaptive radix tree  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-committers
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 main
technique that makes it adaptive is using several different node types,
each with a different capacity of elements, and a different algorithm
for accessing them. The nodes start small and grow/shrink as needed.

The main advantage over hash tables is efficient sorted iteration and
better memory locality when successive keys are lexicographically
close together. The implementation currently assumes 64-bit integer
keys, and traversing the tree is in general slower than a linear
probing 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 further
reduce memory usage and speed up traversal, but the former would add
significant complexity and the latter requires storing the full key
with the value. We do trivially compress the path when leading bytes
of the key are zeros, however.

For value storage, we use "combined pointer/value slots", as
recommended in the paper. Values of size equal or smaller than the the
platform's pointer type are stored in the array of child pointers in
the last level node, while larger values are each stored in a separate
allocation. This is for now fixed at compile time, but it would be
fairly trivial to allow determining at runtime how variable-length
values are stored.

One innovation in our implementation compared to the ART paper is
decoupling the notion of node "size class" from "kind". The size
classes within a given node kind have the same underlying type, but
a variable capacity for children, so we can introduce additional node
sizes with little additional code.

To enable different use cases to specialize for different value types
and for shared/local memory, we use macro-templatized code generation
in 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 of
credit is due to Andres Freund, whose proof-of-concept was a valuable
source of coding idioms and awareness of performance pitfalls, and
who reviewed earlier versions.

Discussion: https://postgr.es/m/CAD21AoAfOZvmfR0j8VmZorZjL7RhTiQdVttNuC4W-Shdc2a-AA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ee1b30f128d8f63a5184d2bcf1c48a3efc3fcbf9

Modified Files
--------------
src/backend/utils/mmgr/dsa.c                       |   13 +
src/include/lib/radixtree.h                        | 3009 ++++++++++++++++++++
src/include/utils/dsa.h                            |    1 +
src/test/modules/Makefile                          |    1 +
src/test/modules/meson.build                       |    1 +
src/test/modules/test_radixtree/.gitignore         |    4 +
src/test/modules/test_radixtree/Makefile           |   23 +
.../test_radixtree/expected/test_radixtree.out     |   41 +
src/test/modules/test_radixtree/meson.build        |   34 +
.../modules/test_radixtree/sql/test_radixtree.sql  |    7 +
.../modules/test_radixtree/test_radixtree--1.0.sql |    8 +
src/test/modules/test_radixtree/test_radixtree.c   |  473 +++
.../modules/test_radixtree/test_radixtree.control  |    4 +
src/tools/pgindent/typedefs.list                   |    1 +
14 files changed, 3620 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Revert "Add recovery TAP test for race condition with slot inval
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Add template for adaptive radix tree