[DMDB] Fix issues, improve query processing with notes on time complexities

This commit is contained in:
2026-07-27 14:41:27 +02:00
parent d197d01f24
commit be2e079959
22 changed files with 142 additions and 34 deletions
@@ -0,0 +1,16 @@
Adaptive Radix Trees (ARTs) are mainly used to ensure primary key constraints and to speed up point and highly selective queries (selectivity <0.1\%).
It can also be manually created using \texttt{CREATE INDEX} and are automatically created for columns with a \texttt{UNIQUE} or \texttt{PRIMARY KEY} constraint.
The above applies to DuckDB, which is often similar to Postgres.
ARTs are not balanced and the internal node size is modified to accommodate the data distribution, thus not requiring nodes to have fixed sizes, which would contain empty pointers.
The internal node size however typically isn't \textit{entirely} variable, but often comes in four different sizes, facilitating traversal.
Each node stores the keys and pointers to the next node to follow for a given key.
Common optimizations includes path compression, where particularly with long keys, some nodes could potentially only contain a single pointer.
These nodes can be collapsed and removed to make the tree smaller (i.e. the pointer in the parent is updated to directly point to the data instead).
If required by insertions, nodes can be added as needed (akin to B+ trees).
For speed, ART require indexed values to be binary-comparable.
This can become an issue with data types such as signed numbers (extra bit for sign), strings (termination character) and nulls (must be mapped to a non-value sequence).
Thus, the data needs to be transformed to be able to index it and search the tree.
@@ -0,0 +1,8 @@
R-Trees are typically used for geospatial datasets, where searching for spatial relationship is expensive (requiring a full table scan).
R-Trees create indexes on bounding boxes as opposed to points in 2- or 3D space.
We can locate the smallest bounding box where a tuple may lay by traversing the index and looking up the leaf to see if the point is there (or to look for a near neighbour).
For more information, see \hlhref{https://en.wikipedia.org/wiki/R-tree}{Wikipedia}
{\scriptsize (yes, they actually just linked to Wikipedia, so it probably isn't very exam-relevant)}
@@ -0,0 +1,7 @@
For groups of data that don't change often, we can compute statistics on insert, such as \texttt{sum}, \texttt{avg}, \texttt{min}, \texttt{max}, etc.
These aggregates can be used to check whether data needed is within that group.
This also enable computing (some) aggregates without reading the entire table and is commonly used in data mining and data cubes.
A concept that is not used in DB engines, is count min sketch. It can be very useful in data streaming engines and large scale data processing.
What this does is it computes statistics on how many times a given value was seen in a list or stream of data and is a variation of the bloom filter,
but with several arrays and counting. The overestimation in count is bounded by the size in the matrix.