Finding #01 · Digest 0x8fa4c219
Order history lookup scans 4.8M rows and spills filesort to disk
The checkout dashboard filtered orders by account_id and status while sorting by created_at DESC. Because only a single-column index on (account_id) existed, InnoDB read 48,200 data pages per call and allocated a disk-backed sort buffer.
Illustrative specimen from a staging benchmark; results depend on the workload; we baseline before and measure after each approved change.
1. Before vs. After EXPLAIN ANALYZE execution plan
SQL · EXPLAIN ANALYZE
-- BEFORE: Filter + disk filesort over single-column idx_account (1,840 ms)
-> Limit: 20 row(s) (actual time=1839.4..1839.6 rows=20 loops=1)
-> Sort: orders.created_at DESC, limit input to 20 row(s)
-> Filter: (orders.status = 'PAID') (rows=4812040 loops=1)
-> Index lookup on orders using idx_account (account_id=49102)
-- AFTER: Covering reverse-scan composite index (11.4 ms)
-> Limit: 20 row(s) (actual time=0.42..11.38 rows=20 loops=1)
-> Index lookup on orders using idx_orders_acct_status_created
(account_id=49102, status='PAID') (reverse)2. Online index rollout & tested rollback DDL
SQL · Online DDL + Rollback
-- Guard metadata lock wait and build composite index online SET SESSION lock_wait_timeout = 2; ALTER TABLE orders ADD INDEX idx_orders_acct_status_created (account_id, status, created_at DESC, total_cents), ALGORITHM=INPLACE, LOCK=NONE; -- Instant optimizer rollback (MySQL 8.0 / 8.4 LTS invisible index toggle) ALTER TABLE orders ALTER INDEX idx_orders_acct_status_created INVISIBLE; -- Or full online drop if required: ALTER TABLE orders DROP INDEX idx_orders_acct_status_created, ALGORITHM=INPLACE, LOCK=NONE;







