Hilbert functions in the Lindel DuckDB extension
Function category
Hilbert
2 functionsHilbert-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.
Signature
hilbert_decode(
encoded_value: <numeric>,
num_elements: UTINYINT,
return_float: BOOLEAN,
return_unsigned: BOOLEAN
) → ANY[ANY]
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
encoded_value
|
Type
<numeric>
5 concrete typesUBIGINTUHUGEINTUINTEGERUSMALLINTUTINYINT
|
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
Reverse the encoding — recover the original N-dimensional array from a Hilbert-encoded integer.
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;
Signature
hilbert_encode(values: ANY[ANY]) → ANY
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
values
|
Type
ANY[ANY]
|
Mode Positional | Description |
Description
Encode a numeric array along the Hilbert space-filling curve into a single sortable integer. Preserves spatial locality better than Morton — values close in N dimensions stay close in the encoded ordering.
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;