Sifat Ullah Sharkar

Making slow queries fast

The workflow I use on any database, PostgreSQL, MySQL or MongoDB: find the slow reads, give each one an index that matches it, and shape the data around how pages read it.

  • 5 steps
  • 2 min
  • Mar 2025 – present
Slow reads
found with EXPLAIN
Documents read
matches only
MongoDB queries
30% faster
db.products.find({ category: "valves" }).sort({ price: 1 }) index { category: 1, price: 1 }fittings · 9pipes · 12pipes · 30pumps · 40pumps · 55valves · 18valves · 25valves · 31 products collectionpumps#101pipes#102pipes#103pumps#104fittings#105pipes#106valves#107pipes#108pipes#109pumps#110fittings#111pipes#112valves#113pipes#114pipes#115pumps#116fittings#117pipes#118valves#119pipes#120pipes#121pumps#122fittings#123pipes#124{ _id: ObjectId(…), name: "Gate valve DN50", category: "valves", price: 25, specs: { size: "DN50", material: "brass" }, supplierId: ObjectId(…)}specs: embedded, read togethersupplierId: referenced, shared COLLSCANdocsExamined: 24 · nReturned: 3sort: in memory IXSCAN → FETCHkeysExamined: 3 · docsExamined: 3sort: from the index queries 30% fasterexample data
  1. 1Measure
  2. 2COLLSCAN
  3. 3IXSCAN
  4. 4Schema
  5. 5Result