- Inspect
- Diagnose
- Apply fix
- Verify
Your mission
The order history endpoint exceeds its SLO after data growth. Database CPU is high, but only one query dominates the slow log.
- workload
- mysql/commerce
- status
- latency degraded
- symptom
- tenant order lookup performs a full table scan
Current objective
Inspect the execution plan on the read replica before proposing an index.
Show a hint
Try: mysql -e 'EXPLAIN ANALYZE SELECT * FROM orders WHERE tenant_id=42 ORDER BY created_at DESC LIMIT 50;' Purpose-built composite index
CREATE INDEX idx_orders_tenant_created ON orders (tenant_id, created_at DESC);
Restart clears this attempt. Completed labs are remembered in this browser.
Incident review
The query reads 50 rows instead of 12.4 million.
The composite index serves the equality filter and requested order without a filesort.
Lesson
Design indexes from observed access patterns, not individual columns. Put equality filters first, then ordering or range columns, verify with the real plan, and remember that every index adds write and storage cost.
Choose another scenarioCommand transcript
Your commands and their output will appear here.
Edit add_orders_tenant_created_index.sql
Create one index that matches the equality filter first and the requested order second.