Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 8 min read Announcement mediumAdept

Introducing pg_re2, fast, RE2-powered regular expressions in Postgres

pg_re2 is a Postgres extension that replaces backtracking POSIX regex with Google's automata-based RE2 engine, beating Postgres builtins by 1.8x to 8.6x on table scans and 1.1x to 1.8x on index scans. The extension adds an `@~` operator with btree and GIN (`gin_re2_ops`) index support, which can use trigram indexes for patterns like `error_code=42[0-9]` where `pg_trgm` falls back to a full scan. It also fixes semantic mismatches with pg_clickhouse pushdown: `\b` means backspace in Postgres but word boundary in ClickHouse, and flags, backreferences and lookarounds differ too. Using pg_re2 functions such as `re2match()` gives the same results whether a query runs locally or is pushed down to ClickHouse.

Assumes: Postgres extensionsregular expressionsforeign data wrappers

Related posts

  • Introducing pg_clickhouse: A Postgres extension for querying ClickHouse

    ClickHouse mediumAdept

    pg_clickhouse v0.1.0 is an Apache 2-licensed PostgreSQL foreign data wrapper, derived from clickhouse_fdw, that runs analytics queries on ClickHouse from Postgres so existing queries can work unmodified by changing search_path. It modernizes the code with PGXS builds, CI across PostgreSQL 13-18 and ClickHouse 22-25, TLS, and Bool/Decimal/JSON types. Its main advance is pushdown: ordered-set aggregates like percentile_cont() are rewritten to ClickHouse quantile() and FILTER clauses become -If combinators. SEMI JOIN pushdown plus planner cost tuning brought 21 of 22 TPC-H queries under 1s, with 12 fully pushed down.

  • ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1

    ClickHouse mediumAdept

    ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine. Simple WHERE clauses are pushed down to Postgres, while aggregation, joins, sorting and LIMIT run in ClickHouse. On the 28M-row UK house price dataset, a low-selectivity filter makes Postgres choose a parallel sequential scan over the index, taking about 28s, and querying through ClickHouse gives similar times because Postgres still does the scan. Queries using ClickHouse-specific functions such as toYear are not pushed down and can run much slower. Rewriting joins with conditional aggregates like medianIf, or copying the data into local MergeTree tables, is what delivers the large speedups.

  • What's New in pg_clickhouse v0.3.2: Postgres 19, TLS, Regex, and Memory

    ClickHouse mediumAdept

    pg_clickhouse v0.3.2, the Postgres extension for querying ClickHouse, adds support for PostgreSQL 19 Beta1 and needs no restart or ALTER EXTENSION UPDATE. New CREATE SERVER options cover TLS behavior (`secure` on/off/auto, `min_tls_version`) and native protocol compression. Regex flag pushdown has been corrected, with a mapping table and a warning that Postgres and ClickHouse treat negated character classes differently around newlines. The release also fixes memory ballooning in repeatedly re-scanned parameterized foreign scans and in unbuffered HTTP queries, pushes down capture-free regexp_match(), and fixes empty-array ANY() errors on older ClickHouse.

  • ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 2

    ClickHouse mediumAdept

    ClickHouse dictionaries backed by a PostgreSQL source can replace joins against Postgres-resident mapping tables, keeping the data in memory and refreshing it via LIFETIME and an invalidate_query. On the UK house price dataset, a regional price-change query took 48.5s in Postgres, 4.1s in ClickHouse when joining through the PostgreSQL table engine, and 0.44s using dictGet against a complex_key_hashed dictionary. The PostgreSQL table engine also supports "reverse ETL": an INSERT ... SELECT can push aggregated monthly price statistics computed in ClickHouse back into a Postgres summary table for a user-facing application to query.

  • pg_search is Available on Neon

    Neon mediumAdept

    ParadeDB's pg_search extension, now available on Neon in AWS regions, adds a Tantivy-powered BM25 inverted index to Postgres, bringing relevance ranking, fuzzy matching, faceting, highlighting and JSON-aware search that native tsvector/GIN full-text search lacks. The BM25 index is a covering index across multiple columns, so filters and aggregations are pushed into a single index scan, and it is MVCC-integrated so new data is searchable on commit without ETL. On a 10-million-row log dataset, it built faster than a GIN index (1.63 vs 2.60 min) but was larger (647 vs 176 MB). It beat a GIN/B-tree-tuned Postgres on every query tested, with the largest gains on ranked top-N, count and filtered queries, e.g. 81 ms vs 38.8 s for BM25-ranked top-10.

The quest for software engineering knowledge.

Look:
Layout: