A query that had been the top entry in the slow log for two years, removed from it by one index.
-- before: 41 seconds, filesort, 2.1M rows examined
SELECT customer_id, SUM(total_minor_units), COUNT(*)
FROM orders
WHERE placed_at >= ? AND status = 'paid'
GROUP BY customer_id;
ALTER TABLE orders ADD INDEX idx_report
(status, placed_at, customer_id, total_minor_units);
-- after: 1.8 seconds, Using index, no filesort
The column order is the design — equality, then the range, then the grouping column, then the payload — and getting it wrong in any position loses the covering property. The index is 180 MB, which is the honest cost and is worth it for a query that runs hourly and was not worth it for the three others we considered.