SipHash functions in the Hashfuncs DuckDB extension
Sample data for the examples
Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.
-- Fixtures for the hashfuncs cookbook / technical-details examples.
--
-- The hashfuncs extension itself is pure CPU (no catalog, no network),
-- so these fixtures only exist to satisfy the *table references* the
-- documentation makes ("FROM events", "FROM users", ...). The numbers
-- chosen are tiny and deterministic so re-running the suite is stable.
--
-- Idempotent: every CREATE uses OR REPLACE.
-- The bitfilters cookbook section pairs hashfuncs with the bitfilters
-- extension. Load it best-effort so xor8_filter / xor8_filter_contains
-- resolve at parse time. If the community binary isn't available on the
-- current platform we still want the rest of the fixtures to apply.
INSTALL bitfilters FROM query_farm;
LOAD bitfilters FROM query_farm;
-- cookbook.mdx — "Hash partitioning" and "Independent hashes via seeds"
CREATE OR REPLACE TABLE users AS
SELECT i AS user_id
FROM range(0, 8) t(i);
-- cookbook.mdx — "Cross-system routing (Cassandra / Spark)"
CREATE OR REPLACE TABLE rows_to_route AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);
-- cookbook.mdx — "String cache keys"
CREATE OR REPLACE TABLE query_log AS
SELECT i AS user_id,
'select ' || i::VARCHAR AS query_text
FROM range(0, 4) t(i);
-- cookbook.mdx — "Bloom / XOR / Cuckoo filter input"
CREATE OR REPLACE TABLE allowed_users AS
SELECT 'user' || i::VARCHAR || '@example.com' AS email
FROM range(0, 4) t(i);
-- cookbook.mdx — second bitfilters block reads from `filter_table f`
-- (a one-row table holding a pre-built xor8 filter).
CREATE OR REPLACE TABLE filter_table AS
SELECT xor8_filter(xxh3_64(email)) AS filter
FROM allowed_users;
-- cookbook.mdx — "Independent hashes via seeds" uses `FROM keys`
CREATE OR REPLACE TABLE keys AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);
-- cookbook.mdx + technical-details.mdx — "events" with event_id, payload
-- Used by sharding / dedup / "magic moment" examples.
CREATE OR REPLACE TABLE events AS
SELECT i AS event_id,
'evt-' || i::VARCHAR AS payload,
'user' || i::VARCHAR || '@example.com' AS email
FROM range(0, 8) t(i);
-- technical-details.mdx — "double-hash with two seeds" reads `FROM data`
CREATE OR REPLACE TABLE data AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);
Function category
SipHash
2 functionsSipHash is a keyed hash: with a secret 128-bit key, an attacker who doesn't know the key can't craft colliding inputs, which protects hash tables and partitioners from hash-flooding. siphash24 is the standard SipHash-2-4; siphash13 is the faster SipHash-1-3 used by Rust's standard library and CPython. Neither is a substitute for a cryptographic digest or MAC — use crypto for those.
Signature
2 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Argument
key
|
Type
UHUGEINT
|
Mode Positional | Description |
Description
SipHash-1-3 — the faster, reduced-round SipHash used by Rust's standard library and CPython 3.11+ for string hashing. Same key handling as siphash24: the optional UHUGEINT key supplies the 128-bit key as its 16 little-endian bytes.
SELECT siphash13('hello world');
Output
| siphash13('hello world') |
|---|
| 12804282289674824842 |
SELECT siphash13('hello world', 20011376718272490338853433276725592320::UHUGEINT);
Output
| siphash13('hello world', CAST(20011376718272490338853433276725592320 AS UHUGEINT)) |
|---|
| 12342443889262022011 |
Related functions
Signature
2 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Argument
key
|
Type
UHUGEINT
|
Mode Positional | Description |
Description
SipHash-2-4, the standard SipHash, returning the 64-bit result as UBIGINT. The optional key is a UHUGEINT whose 16 little-endian bytes are SipHash's 128-bit key; without a key, all key bytes are zero — which matches ClickHouse's sipHash64 of a String.
With a secret key, SipHash resists hash-flooding: an attacker who doesn't know the key can't craft inputs that collide. It is still not a MAC or digest — use crypto for those.
SELECT siphash24('hello world');
Output
| siphash24('hello world') |
|---|
| 6266945022561323786 |
SELECT siphash24('hello world', 20011376718272490338853433276725592320::UHUGEINT);
Output
| siphash24('hello world', CAST(20011376718272490338853433276725592320 AS UHUGEINT)) |
|---|
| 17100547981382080002 |