Debugging MongoDB queries with explain('executionStats')
totalKeysExamined, totalDocsExamined, nReturned — the three numbers I look at first, and what their ratios tell me before I read a single index.
Query plans, index internals, GC pauses, replica lag. Long-form, code-first, no preamble. Two new articles each week from engineers who've been on call.
Equality, Sort, Range — the three letters that decide whether your compound index is a thoroughbred or a paperweight. We dissect the planner's prefix-matching logic on a 40M doc collection.
totalKeysExamined, totalDocsExamined, nReturned — the three numbers I look at first, and what their ratios tell me before I read a single index.
How to fake LIKE '%foo%' on Mongo with trigrams, a pre-computed token array, and a clever multikey index. ~12ms p99 on 8M documents.
Seq scan, index scan, index-only scan, bitmap heap scan, TID scan. When the planner picks each, and what it means when you see the wrong one.
shared_buffers, work_mem, effective_cache_size, and five more — what they really do, how to size them, and which defaults are still stuck in 2008.
If your index has every column the query needs, the database never has to fetch the row. Here's how to recognise the opportunity — and the storage trade.