Skip to content

Hilbert functions in the Lindel DuckDB extension

Function category

Hilbert

2 functions

Hilbert-curve encoding — best locality preservation. Slightly slower to compute than Morton but produces tighter row groups when used as ORDER BY in Parquet, leading to better predicate skipping at query time.

hilbert_decode

Scalar function Hilbert
Signature
hilbert_decode( encoded_value: <numeric>, num_elements: UTINYINT, return_float: BOOLEAN, return_unsigned: BOOLEAN ) ANY[ANY]
Arguments (Positional)
Argument encoded_value Type <numeric>
5 concrete types
UBIGINTUHUGEINTUINTEGERUSMALLINTUTINYINT
Mode Positional Description
Argument num_elements Type UTINYINT Mode Positional Description
Argument return_float Type BOOLEAN Mode Positional Description
Argument return_unsigned Type BOOLEAN Mode Positional Description
Description
1 Round-trip an encoded integer back to its components (num_elements, return_float, return_unsigned)
SELECT hilbert_decode(hilbert_encode([10, 20]::UINTEGER[2]), 2, false, true) AS roundtrip;

hilbert_encode

Scalar function Hilbert
Signature
hilbert_encode(values: ANY[ANY]) ANY
Arguments (Positional)
Argument values Type ANY[ANY] Mode Positional Description
Description
1 Order points by the Hilbert curve so (x, y) neighbors stay adjacent
SELECT x, y, hilbert_encode([x, y]::UINTEGER[2]) AS hilbert
FROM (VALUES (1, 1), (1, 2), (2, 1), (6, 7), (7, 6)) AS t(x, y)
ORDER BY hilbert;