Data UI Backlog

Trigram indexes for searchable fields

:searchable t fields get no index today: sort-index-ddl (lisp/model.lisp) emits CREATE INDEX only for :sortable fields, and the search path compiles to col ILIKE $N with a %term% pattern (phase-a-search-clause, lisp/backend.lisp). A leading % defeats a B-tree index, so a plain index on searchable columns would never be used — the code comments say as much ("No search index: leading % defeats btree").

The fix: CREATE EXTENSION pg_trgm plus CREATE INDEX ... USING gin (col gin_trgm_ops) per searchable column. Postgres can satisfy an ILIKE %term% predicate from a trigram GIN index, so the read path needs zero changes — the existing bind-param SQL picks the index up via the planner.

Caveats: search terms under 3 characters have no complete trigram, so those queries still fall back to a seq scan; GIN adds write cost on insert/update; the extension must exist in the Postgres image and CREATE EXTENSION needs privileges, so the model compiler (which would emit the DDL) and the deployment image both need to account for it.

Gated on measured need: only worth doing when a searchable dataset is large enough that seq scans actually hurt. MVP-scale apps (Model Bank, demos) are fine without it.

Slot
28700
Status
10 Open
Tags
backend, model, deployment, perf
Contributors
Donnie, Rosie