Five million books, under 100 ms — SQL LIKE scans and the document-term flip
Substring scans on a million-row table cannot serve ranked search at interactive latency, so the relation between document and term has to be flipped before any other mechanism is worth discussing.
Scene 01
Five million books, under 100 ms
- Watch
- Try it
- Predict
- Capture
The query 'distributed systems' starts a row-by-row sweep over 5,000,000 books. Watch the wall-clock meter and the rows-scanned meter climb together — and watch the 100 ms line fly by.
Highlighted lines are the ones running in the diagram right now.
def naive_scan(query):results = []for book in books: # 5,000,000 rowsif not contains(book.body, query.terms):continue # most rows go hereresults.append(book)return results # cost: O(rows), not O(matches)
Where this sits in Build a distributed search engine (Elasticsearch / OpenSearch style)
Scene 01 of 12. 5M books, a search box, and a 100ms budget — the naive scan-every-row plan never crosses the line, no matter the cores or the disk.
Up next. Scanning every book asks 'does this row contain the term?' five million times. Asking the inverse — 'which rows contain this term?' — makes the answer fall out in two lookups, if you build the right table.
All 12 scenes in Build a distributed search engine (Elasticsearch / OpenSearch style) · Every curriculum