Repository navigation
pg_tre 1.5.6
pg_tre 1.5.6 is now available.
pg_tre is a native index access method (USING tre) for PostgreSQL 18+
that accelerates approximate ("fuzzy") regular-expression search over
text columns. It turns the classic "find text that looks like this,
maybe with a typo" problem into a SQL-composable indexed query, backed
by the TRE approximate-regex library for the exact edit-distance
recheck.
SELECT id FROM docs
WHERE body %~~ tre_pattern('(error){~1}.*(42[0-9]){~0}', 1);
-- Bitmap Index Scan on docs_tre -> sub-millisecond on 10k rows.
A three-tier filter funnel (BRIN-style per-block-range bloom ->
per-trigram sparsemap posting trees -> per-tuple bloom) narrows the
candidate set before any heap recheck, so the executor never touches
the heap for rows the cheaper tiers have already eliminated.
What's new in 1.5.6
This is a robustness and DoS-hardening release on the 1.5.0 lineage.
There is no on-disk format change (still v5) and no REINDEX is
required; the upgrade is a plain ALTER EXTENSION.
-
Multi-level pending-list merge. Large indexes that had grown a
multi-level internal "upper" tree could previously fail their next
incremental merge with an error demanding a full REINDEX. The merge
now descends the whole upper subtree, so ongoing INSERT + VACUUM
workloads merge cleanly at any scale. -
Faster posting merge. A pathological O(TID-range) scan in the
posting-merge path that could spin a CPU for minutes on trigrams
whose matches span a wide TID range has been replaced with a
rank-order iteration that is linear in the number of matches. -
pg_tre.compile_timeout_ms is now enforced. A real wall-clock
deadline is armed around regex compilation, so a pathological
pattern (e.g. deeply nested bounded repetitions like a{80}{80}{80})
is now aborted with a cancellation error instead of being able to
burn compile time unbounded. This complements the existing
pg_tre.match_timeout_ms and pg_tre.max_nfa_states guardrails.
See SECURITY.md for the full description of the DoS guardrails and
exactly what each one bounds.
Highlights of the 1.5.x line
- Approximate (edit-distance k) and exact regex matching with a
bitmap/index scan plan and a planner cost model. - UTF-8 aware trigram extraction.
- Multi-leaf range tier (tier-1 selectivity over 100% of the heap).
- A <@> similarity operator.
- VACUUM that reclaims emptied posting leaves back to the index free
space map (nbtree-style deferred page deletion + recycle). - Single-node crash-recovery correctness via a custom WAL resource
manager (testable with wal_consistency_checking = 'pg_tre').
Requirements
- PostgreSQL 18 or newer.
- MIT licensed. Bundles the TRE library (BSD-2-Clause).
Get it
Source, docs, and issue tracker:
https://codeberg.org/gregburd/pg_tre
GitHub mirror:
https://github.com/gburd/pg_tre
Install (from a source checkout):
make
make install
# then, in your database:
CREATE EXTENSION pg_tre;
CREATE INDEX docs_tre ON docs USING tre (body);
Upgrading from an earlier 1.5.x:
ALTER EXTENSION pg_tre UPDATE TO '1.5.6'; -- no REINDEX needed
Feedback, bug reports, and patches are welcome via the Codeberg issue
tracker.
-- The pg_tre developers