Skip to content

Marisa

Static, space-efficient MARISA trie data structures for DuckDB.

34,792
extension loads · last 90 days
On this page

Technical Overview

Prefix questions answered in key-length time

Why a trie answers both questions at the same cost

How it works

  • Built once into a self-contained BLOB: An aggregate consumes a VARCHAR column at write time and emits one immutable BLOB. Store it wherever DuckDB stores BLOBs — a table column, a Parquet file, an S3 object — and ship it anywhere DuckDB runs. Loading is essentially a pointer-walk; there is no parse or decompression step at query time, and lookups pay no synchronization cost because nothing mutates.
  • Succinct: packed near the information-theoretic minimum: The static design is what lets the structure encode itself close to the theoretical lower bound for the key set. Prefix-rich data — URLs, file paths, names, dictionary words — compresses sharply because shared prefixes are stored once. A ~470K-entry English wordlist lands around 800 KB, roughly a fifth the size of the same words as a flat sorted list, before any column compression.
  • Cost scales with the key, not the dictionary: Because lookup is a path walk of length O(|key|), query latency stays flat as the dictionary grows. Bigger sets buy you a bigger BLOB, not slower queries.

When to choose something else

  • Static — no incremental insert or delete: The immutability that makes the trie succinct also means it can't be edited in place. To add or remove keys, rebuild from the updated source set — milliseconds for a daily wordlist, but an offline build step for billions of keys. A set that churns continuously wants a hash set or a bitfilters Quotient filter instead.
  • VARCHAR keys only: Strings in, strings out, in lexicographic order. Numeric or composite keys must be encoded as text upstream, and a different query-time ordering means building a separate trie.
  • Uncorrelated keys: pick a Bloom: The compression and the prefix queries both depend on shared prefix structure. For pure yes/no membership on random, unrelated strings, a Bloom / XOR / Binary Fuse filter from bitfilters is smaller and just as fast — at the cost of bounded false positives and an inability to return the strings or answer prefix queries. Reach for MARISA when you need the keys back or you need prefixes; reach for bitfilters when memory is the only constraint.

Deep Dive

Technical Details

Install

INSTALL marisa FROM community;
LOAD marisa;

Quick Start

Build a trie from a column

CREATE OR REPLACE TABLE employees(name TEXT);
INSERT INTO employees VALUES ('Alice'),('Bob'),('Megan'),('Melissa');
CREATE OR REPLACE TABLE employees_trie AS
  SELECT marisa_trie(name) AS trie FROM employees;

Membership test

SELECT marisa_lookup(trie, 'Alice') FROM employees_trie;

Autocomplete: names starting with 'Me'

SELECT marisa_predictive(trie, 'Me', 10) FROM employees_trie;

Reference

Extension Contents

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

Name Description
Build
marisa_trie() Aggregate that builds a MARISA trie from a column of strings.
Query
marisa_common_prefix() Returns VARCHAR[] — every string in the trie that is a prefix of the search string, capped at max_results.
marisa_lookup() Returns BOOLEANtrue iff the search string is in the trie.
marisa_predictive() Returns VARCHAR[] — every string in the trie that starts with the given prefix, capped at max_results.

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
34,792
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.28 MB
Linux aarch64 2.91 MB
macOS Intel 1.49 MB
macOS Apple Silicon 1.35 MB
Windows x86_64 7.41 MB
WASM eh 53.9 KB
WASM mvp 53.7 KB
WASM threads 41.7 KB

Compressed download size from the Haybarn extension repository.

DuckDB & Haybarn

Release calendar