When database search is insufficient
coreintermediateA relational database's indexes (B-trees, hashes) are built to find rows by exact value or by range on a known column — "id = 5" or "created_at between X and Y." They are not built to answer "which documents contain words similar in meaning to this phrase, ranked by how relevant each one is." A LIKE '%term%' query can't use a B-tree index at all, so it falls back to scanning every row and string-matching inside it — correct, but linearly slow, and it still can't rank results, tolerate typos, understand word forms (run/running/ran), or search across many fields at once with one relevance score. Once a product needs free-text search with relevance ranking, typo tolerance, faceted filtering, or search across millions of documents with sub-second latency, that's the signal to bring in a dedicated search engine instead of asking the primary database to do more.
Think of it as
A B-tree index is like a library's card catalog sorted by exact title or author name — perfect for "find the book titled exactly this," useless for "find every book that discusses something like this topic, ranked by how central the topic is to each one." For the second question you need a completely different tool: an index built from every word inside every book, not just each book's title card.
What we're doing: Show why a leading-wildcard LIKE query degrades as a table grows, and what it still can't do even when it finishes.
- 6
- The range predicate on published_at can use a normal B-tree index — this is what relational indexes are built for.
- 10
- The leading % in the LIKE pattern means no B-tree can be used; the database must scan and string-match every row.
- 15
- Even a successful full-table scan still cannot rank, fuzzy-match, or understand related terms — that requires a different indexing structure entirely, not just a faster scan.
Why this works: The failure mode isn't just "slow" — it's "the wrong tool," because even an infinitely fast substring scan still can't produce ranked, typo-tolerant, semantically related results the way a search engine's inverted index and scoring model can.
Trying to fix a relevance problem by adding more B-tree indexes
Wrong
Better
What you see: Adding indexes to every text column doesn't fix search relevance or leading-wildcard query speed, because a B-tree was never the right structure for the problem in the first place.
Why: B-tree indexes accelerate equality and range lookups on ordered values — they have no mechanism for tokenizing text into searchable terms or scoring how relevant a document is to a query, so no amount of additional B-tree indexing closes that gap.
- B-tree / hash index
- Fast exact match / range on a column
- Leading-wildcard LIKE forces a full scan
- No relevance ranking, typo tolerance, or facets
- Dedicated search engine
- Native substring/leading-wildcard matching
- Relevance ranking is a core feature
- Stemming, synonyms, faceted counts built in
What a B-tree index handles vs. what free-text search needs
Remember: A B-tree finds exact values and ranges; it can't rank relevance, tolerate typos, or match leading wildcards without a full scan. Reach for a dedicated search engine once ranking, fuzzy matching, or faceting outgrows the database's built-in full-text search — not before.
See also: inverted index and ranking pipeline · search engines as specialized not primary

