Skip to content

Hashfuncs

Fast, deterministic, non-cryptographic hash functions β€” xxHash, MurmurHash3, RapidHash.

5,823,691
extension loads Β· last 90 days
On this page

Technical Overview

Fast, non-cryptographic hashes for keys and buckets

What it is

Hashfuncs vs. crypto β€” picking the right extension

  • β€’ Use hashfuncs when speed wins: Partitioning, sharding, deduplication, cache keys, Bloom-filter inputs β€” workloads where the adversary is randomness, not a human. xxh3_64 and rapidhash run roughly an order of magnitude faster than SHA-256.
  • β€’ Use crypto when collisions must be hard to forge: Digital signatures, HMAC, content-addressed storage with adversarial input, tamper-evident audit logs, password salts, secure random bytes β€” anything an attacker could try to break. The crypto extension gives you BLAKE3, SHA-2, SHA-3, HMAC, and a CSPRNG.
  • β€’ Don't substitute one for the other: These hashes are explicitly not collision-resistant against a motivated adversary. Treating an xxh3_128 like a SHA-256 digest is a security bug, not a performance optimization. The inverse is also wrong: spending SHA-256 on partition routing is wasted CPU. (For password storage, neither family is the answer β€” use a real password hash like bcrypt or argon2 outside DuckDB.)
  • β€’ They compose: Both extensions can be loaded together. A common pattern: crypto for the durable identity hash on a row, hashfuncs for the routing hash that decides which shard processes it.

How it works

  • β€’ Three families, one interface: xxHash (32 / 64 / 128-bit, including a hex digest; XXH3 variants are tuned for SSE2 / AVX2 / NEON), MurmurHash3 (32-bit plus x86 and x64 128-bit forms), and RapidHash, a newer 64-bit hash that often wins published throughput benchmarks. Every function accepts any DuckDB scalar value as input.
  • β€’ Optional seeds for independent hash spaces: Every function has a seeded overload. Two different seeds give two uncorrelated hash spaces from the same column β€” exactly what you need for double-hashing in Bloom filters or running two parallel shardings whose bucket assignments must not correlate.
  • β€’ Canonical hex digest for cross-language reproducibility: The 128-bit xxHash variant can emit the lowercase 32-character canonical hex form defined in the xxHash specification, in low64 || high64 byte order. That digest matches what Python xxhash, xxhash-rust, and XXH128_canonicalFromHash in C produce over the same bytes β€” so a fingerprint round-trips across SQL and application code.
  • β€’ Feeds the bitfilters extension directly: The 64-bit UBIGINT-returning hashes (xxh3_64, rapidhash) are the natural input to the bitfilters extension's Bloom, XOR, Quotient, and Binary Fuse filters β€” sub-microsecond probabilistic set-membership built entirely in one DuckDB session.

Deep Dive

Technical Details

Install

INSTALL hashfuncs FROM community;
LOAD hashfuncs;

Quick Start

64-bit xxHash3 β€” recommended general-purpose default

SELECT xxh3_64(payload) AS h FROM events;

Seeded for reproducible partitioning

SELECT xxh3_64(user_id, 42) % 16 AS partition FROM users;

128-bit hex digest (canonical xxhash byte order; matches Python xxhash.xxh3_128().hexdigest())

SELECT xxh3_128_hex('hello') AS digest;

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Name Description
MurmurHash3
murmurhash3_128() 128-bit MurmurHash3 β€” the x86 variant.
murmurhash3_32() 32-bit MurmurHash3.
murmurhash3_x64_128() 128-bit MurmurHash3 β€” the x64 variant.
RapidHash
rapidhash() RapidHash β€” a 64-bit non-cryptographic hash designed for exceptional speed while keeping competitive distribution quality.
xxHash
xxh3_128() 128-bit xxHash3 (XXH3_128) returned as a UHUGEINT.
xxh3_128_hex() 128-bit xxHash3 returned as a 32-character lowercase hex string in canonical xxHash byte order (low64 || high64), as defined by the xxHash specification.
xxh3_64() 64-bit xxHash3 (XXH3_64) β€” the modern xxHash variant tuned for vectorized CPUs (SSE2/AVX2).
xxh32() 32-bit xxHash (XXH32) β€” the classic 32-bit member of the xxHash family.
xxh64() 64-bit xxHash (XXH64).

API Reference

Function Documentation

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
5,823,691
loads Β· last 90 days

Platforms

  • Linux x86_64 aarch64
  • Linux (musl) Not available
  • macOS Intel Apple Silicon
  • Windows x86_64
  • WASM eh mvp threads
Compiled binary sizes
Platform Architecture Size
Linux x86_64 3.24 MB
Linux aarch64 2.88 MB
macOS Intel 1.49 MB
macOS Apple Silicon 1.35 MB
Windows x86_64 7.40 MB
WASM eh 33.9 KB
WASM mvp 28.4 KB
WASM threads 46.5 KB

Compressed download size from the Haybarn extension repository.

DuckDB & Haybarn

Release calendar