Search queries scan every row Because LIKE '%keyword%' cannot use an index

Your search feature uses WHERE name LIKE '%keyword%' which scans every row in the table. It is tolerable today, and it gets slower with every row you add.

  • Target: search under 15ms
  • Fix shipped in 30 days
  • Full scans Scanned on every search query
  • Growing Current query time (growing linearly)
  • <15ms Target with tsvector full-text search

How it shows up

For teams whose search feature uses LIKE queries that scan every row and slow down linearly as data grows. LIKE is not a search engine. It is a string matching operator that scans every row.

What this sprint implements

  • tsvector columns with GIN indexes on search-critical tables
  • ts_query search with relevance ranking replacing LIKE queries
  • Text search dictionaries for stemming and stop word handling

Sequential scan: O(n) on every query

WHERE name LIKE '%keyword%' with a leading wildcard cannot use a B-tree index. PostgreSQL reads every row. On a small table that is tolerable. On a big one it takes seconds. The growth is linear and inevitable.

No relevance ranking: results in insertion order

LIKE returns all matching rows with no ranking. A product named 'Wireless Keyboard' and a review mentioning 'keyboard' are treated equally. Users get irrelevant results because there is no concept of match quality.

No stemming or fuzzy matching

LIKE '%run%' matches 'running' but not 'ran.' It does not handle typos, plurals, or word variations. tsvector's 'english' dictionary stems words to their root, so 'swimming lessons' and 'swim lesson' resolve to the same lexemes and match. LIKE has no concept of this, so users lose relevant content to exact-match limitations.

Who it is for

Best fit when your search is slow or returning poor results and you want to fix it without adding Elasticsearch.

Good fit

  • Applications with LIKE queries on large tables
  • Products where search quality complaints are growing with the data
  • Teams that want search improvements without adding external infrastructure

Why teams keep using LIKE queries

LIKE works until it does not.

Repeated failure patterns

  • LIKE was fast on a small table so the team assumed it would scale
  • The team plans to add Elasticsearch 'when search becomes important,' but it already is
  • Adding a B-tree index does not help because LIKE '%x%' has a leading wildcard

What we do in 30 days

We implement tsvector search with ranking, fuzzy matching, and autocomplete, all within PostgreSQL.

  1. Days 1-5: Search audit

    Map all search queries in the application. Measure current performance. Identify which tables need tsvector columns. Configure text search dictionaries for your content language.

  2. Days 6-14: Core search

    Add tsvector columns and GIN indexes. Rewrite queries to use websearch_to_tsquery with ts_rank for relevance ordering, so real user input maps cleanly to a ranked bitmap index scan instead of a sequential scan. Proof release target: search under 15ms with ranked results.

  3. Days 15-24: Advanced features

    Add pg_trgm for fuzzy matching and typo tolerance. Implement search suggestions with trigram similarity. Add search result highlighting.

  4. Days 25-30: Monitoring and handoff

    Search performance monitoring. Query analytics for common searches. Handoff with search operations guide and index maintenance schedule.

What you get

Fast, relevant, fuzzy-tolerant search, all within PostgreSQL with no external services.

Search features

  • tsvector full-text search with GIN indexes (target under 15ms)
  • Relevance ranking with ts_rank
  • Fuzzy matching with pg_trgm for typo tolerance

Operations

  • Search performance monitoring dashboard
  • Index maintenance schedule and procedures
  • Guide for adding search to new tables

Why Pineido

We implement search in the database you already have.

PostgreSQL-native approach

PostgreSQL's full-text search handles most application search needs, even on large tables. A GIN-indexed tsvector turns search into a bitmap index scan whose cost scales with the number of matches, not the size of the table. Add ts_rank for relevance and pg_trgm for fuzzy matching and you get most of what Elasticsearch offers without running a second system.

Full scans Scanned on every search query

Replace LIKE queries with real full-text search

From full table scans to a 15ms target.

Fixed scope, fixed price.

You leave with

  1. Search audit and query mapping within 5 days
  2. tsvector indexes and ranked search live by day 14

What people ask us first

At what scale should we switch to Elasticsearch?

PostgreSQL full-text search handles most use cases with proper indexing, even on large tables. Beyond that, or if you need complex faceted search, multi-language search across the same index, or real-time indexing of a heavy document stream, Elasticsearch becomes worth the operational cost.

Does this work with Supabase?

Yes. Supabase runs standard PostgreSQL with pgvector and pg_trgm available. We add the tsvector as a generated column so it stays in sync automatically, build a GIN index on it, and expose a search function using websearch_to_tsquery and ts_rank. That function is called via supabase.rpc() from the client, so search syntax with quotes and negation works the way users expect.

Will adding tsvector columns increase storage significantly?

tsvector columns make rows in text-heavy tables bigger, and the GIN index takes extra space on top. We measure the added storage on your table before you commit. For search that has to stay fast, the trade-off is usually worth it.

How does fuzzy matching work in PostgreSQL?

We use the pg_trgm extension, which breaks text into three-character trigrams and scores how many two strings share. With a gin_trgm_ops index and a tuned similarity threshold, a search for 'recieve' still finds 'receive' and 'Jonathon' still finds 'Jonathan.' Combined with tsvector for ranked results, you get a search experience that feels like Google without an external search engine.

Can you implement search suggestions and autocomplete?

Yes. We build a suggestion index from your most common search terms and high-value content titles. As the user types, trigram matching returns ranked suggestions almost instantly. The suggestions update automatically as your content changes. No manual curation needed.

How do you keep tsvector columns in sync when content changes?

For search over a single table we use a generated column, so PostgreSQL recomputes the tsvector automatically on every insert and update with no trigger to maintain. When search has to pull text from related tables, generated columns cannot reference them, so we use a trigger instead. Either way the rebuild is automatic and adds very little to each write. Your application code never manages search indexing. It happens transparently at the database level.

ByFounder and Imaginator

Published Updated