Back to gallery
planetscale/lead on GitHub — A non-production Postgres text-search extension for exercising TIN-compatible application SQL in development, test, CI, and staging environments
planetscale
Built byplanetscale/

lead

A non-production Postgres text-search extension for exercising TIN-compatible application SQL in development, test, CI, and staging environments

Stars
170
Forks
10
Watchers
170
Open issues
0
RustAGPL-3.0 main Updated 1 month ago~3 stars/day lifetime
Editor's take

Lead is PlanetScale's deliberately non-production Postgres text-search extension that implements the TIN access method and TINQL query syntax for development, test and CI. It matters if your production database uses PlanetScale's TIN search: you can run the same application SQL locally in a plain Postgres 17 or 18 container. The tradeoff is the whole design: every index scan returns every heap page and Postgres rechecks the rows, so it is correct but slow, and the authors say clearly it is unsuitable for production. The fuller test suite also needs access to the private TIN source. Prebuilt images are on Docker Hub as planetscale/lead. AGPL-3.0, from PlanetScale, about 170 stars.

Use this if

Your production Postgres on PlanetScale uses TIN full-text search and you want the same queries working in CI.

Skip if

You are not on PlanetScale; use Postgres built-in full-text search or ParadeDB instead.

Database & ORMSearchTesting
Quick install
# Add to Cargo.toml:
cargo add lead

Inferred from Rust · always double-check against the official README below.

README — rendered from planetscale/lead

Lead

Lead is a deliberately non-production Postgres text-search extension for exercising TIN-compatible application SQL in development, test, CI, and staging environments.

It favors correctness and a small implementation over production query performance.

It is intentionally unsuitable for production workloads. Every index scan returns all heap pages as candidates; Postgres rechecks their visible rows for exact TINQL and MVCC behavior. The index stores no search data.

Build

Install cargo-pgrx version 0.19.1 exactly and initialize it for the Postgres major versions you need, then build or package with one version feature:

cargo pgrx package --package tin --no-default-features --features pg18

For an interactive development database, run:

cargo pgrx run pg18 --package tin

Then run CREATE EXTENSION tin in the database. Lead loads on demand and does not require shared_preload_libraries or session_preload_libraries.

Docker

The Dockerfile builds an image of the official Postgres image plus Lead. It is a debug build on purpose, with debug assertions and full stack traces, for development and CI. Do not use it in production.

docker build --build-arg PG_MAJOR=18 -t lead:pg18 .

PG_MAJOR can be 17 or 18. To build for both architectures, use buildx:

docker buildx build --platform linux/amd64,linux/arm64 --build-arg PG_MAJOR=18 -t lead:pg18 .

Run the image like the official Postgres image. It runs CREATE EXTENSION tin in the default database on first start:

docker run -d --name lead -p 5432:5432 -e POSTGRES_PASSWORD=secret lead:pg18
psql postgresql://postgres:secret@localhost:5432/postgres
docker exec -it lead psql -U postgres

Prebuilt images for amd64 and arm64 are on Docker Hub as planetscale/lead:pg17 and planetscale/lead:pg18 (also latest), and as planetscale/lead:<version>-pg<N>. Each push to main also publishes planetscale/lead:<commit>-pg<N>, where <commit> is the first 12 characters of the commit hash, so you can pin an exact build.

Compatibility boundary

Lead provides the tin access method, the ==> operator, TINQL parsing, tokenizer and index reloptions (including the Snowball stemmer option), and the scoring functions tin.score, tin.full_score, tin.max_score, and tin.score_inspect, plus explicit and implicitly bound tin.highlight and tin.highlight_ansi. Postgres 17 and 18 are build targets. Search results are exact because the access method returns whole-page candidates and Postgres evaluates ==> against each visible heap tuple, including expression and partial-index rechecks.

The planner binds each ==> and each tin.highlight or tin.highlight_ansi call to the analysis of the tin index that covers its column, so a stemmed index matches and highlights inflected words in queries over that column, including joins, partitions, and cached plans. That includes body ==> ANY(...), whose array elements are bound to the index analysis too; tin.highlight marks only the implicit queries of plain ==> quals, as TIN does, though an ANY(...) search binds the analysis of an explicit query. tin.tokenize, tin.ql_parse, tin.highlight, and tin.highlight_ansi take a trailing stemmer argument as in TIN 1.0.4; their 1.0.3 signatures remain as tin.tokenize_v1_0_3, tin.ql_parse_v1_0_3, tin.highlight_v1_0_3, and tin.highlight_ansi_v1_0_3. As in TIN, changing stemmer on an existing index requires REINDEX.

Scoring deliberately rescans and retokenizes the visible indexed column or expression, once per statement and search, under that statement's snapshot. A score call must be in the same query level as the matching ==> predicate, and a partial tin index binds only when the query's quals imply its WHERE condition, as in tin. Implicit highlighting binds the same way and, like tin, returns the text unmarked when no index binds a search; passing its query argument explicitly works without a bound predicate.

Execution and storage

Each scan reads the table's current block count and adds every block to a lossy bitmap. Postgres owns row visibility, query rechecks, and table maintenance. Index builds evaluate indexed expressions and predicates for validation and statistics; inserts and VACUUM have no index entries to maintain.

Lead allocates no extension shared memory and creates no files outside Postgres's normal relation storage. Server restarts and crash recovery do not require rebuilding Lead indexes: scans use the recovered heap directly.

Tests

Run the local unit and Postgres tests for a supported Postgres major version with:

cargo pgrx test pg18 --package tin --no-default-features --features pg18

Developers with access to the TIN private source may also run the more comprehensive test suite that comes with that:

TIN_PRIVATE_REPO=/path/to/full-tin script/run-private-regress pg18

TINQL guide

The TINQL guide documents the query language. To build it with mdBook, run from the repository root:

cargo install mdbook --version 0.5.2 --locked
mdbook build tinql/docs

Open tinql/docs/book/index.html in your browser to read the book.

Contributing

We intend for Lead to be a slow but correct substitute for TIN, for use at small scales in development and testing environments. If you find cases where it's unsuitable for that, please contact PlanetScale through normal support channels or open an issue in this repo. The most helpful bug reports will include information about what you expected Lead to do (which is normally whatever TIN would do in the same situation) versus what it actually did. Help us recreate the problem so we can fix it.

Live data via GitHub REST API · Cached 30 min · Created 17 Sept 2026