Optimizing Postgres Text Search with Trigrams - Alex Klibisz
We’ll start with some fundamental concepts, then define a test environment based on a dataset of 8.9 million Amazon reviews, then cover three possible optimizations. Our search will start very slow, about 360 seconds. With some thoughtful optimization we’ll end up at just over 100 milliseconds – a ~3600x speedup! These optimizations won’t apply perfectly to every text search use-case, but they should at the very least spark some ideas. For our purposes, “text search” is defined as follows: Postgres is a ubiquitous relational database, but dedicated search systems like Solr, Elasticsearch, and Opensearch are far better-known for text search. Still, Postgres offers some competent text search functionality, with several benefits over a dedicated search system: Having implemented and operated search functionality on both Postgres and Elasticsearch, my current heuristics for choosing between them are: As a case-study, Gitlab has publicly documented their journey in growing from Postgres tri
Introduction In this post, we’ll implement and optimize a text search system based on Postgres Trigrams . We’ll start with some fundamental concepts, then define a test environment based on a dataset of 8.9 million Amazon reviews, then cover three possible optimizations. Our search will start very slow, about 360 seconds. With some thoughtful optimization we’ll end up at just over 100 milliseconds – a ~3600x speedup! These optimizations won’t apply perfectly to every text search use-case, but they should at the very least spark some ideas. Defining “text search” For our purposes, “text search”
Explore this link on the map →related reading
- Fast regex search: indexing text for agent tools · Cursorcursor.com
- Regular Expression Matching with a Trigram Indexswtch.com
- Create an advanced search engine with PostgreSQL | xataxata.io
- Postgres as a search engine / anyblockersanyblockers.com
- Full Text Search | Supabase Docssupabase.com
- Full-text search engine with PostgreSQL (part 2): Postgres vs Elasticsearch | xataxata.io
- Building a web search engine from scratch in two months with 3 billion neural embeddingsblog.wilsonl.in
- Faiss: A library for efficient similarity search - Engineering at Metaengineering.fb.com
- string - Data structure for fast full text search - Stack Overflowstackoverflow.com
- PostgreSQL Index Types - Vlad Mihalceavladmihalcea.com
- Announcing ScaNN: Efficient Vector Similarity Searchai.googleblog.com
- Static search trees: 40x faster than binary search · CuriousCodingcuriouscoding.nl