PostgreSQL full-text search can become slow at scale when tsvectors are computed on-the-fly during queries. By persisting tsvectors in a dedicated column with a GIN index, query performance improved 118× (from ~283ms to ~2.4ms) on 100k rows. The optimization shifts PostgreSQL from sequential scans to bitmap index scans,
Table of contents
A Simplified ExampleSetup SearchUsageOn-The-Fly TSVectorsPersist TSVectorsPerformance After the FixLesson LearnedSort: