The Apex Analytics dashboard has been timing out. The culprit is a query on the transactions table โ 500,000 rows, no indexes. Your job is to diagnose the query plan with EXPLAIN, identify the bottleneck, and create the right indexes to bring execution time under 200ms.
SELECT * FROM transactions WHERE amount > 1000 AND status = 'completed' ORDER BY created_at DESC LIMIT 50;
Currently taking ~4,200ms. Unacceptable for a dashboard.
EXPLAIN SELECT * FROM transactions WHERE amount > 1000;SHOW INDEX FROM transactions;CREATE INDEX idx_amount ON transactions(amount);CREATE INDEX idx_status_amount ON transactions(status, amount);CREATE INDEX idx_status_amount_date ON transactions(status, amount, created_at);EXPLAIN ANALYZE SELECT ...;DROP INDEX idx_name ON transactions;A composite index on (status, amount) will be more effective than individual indexes because MySQL can use it for both the WHERE clause and avoid a filesort. Try both and compare the profiler results.