Full explanation
Performance Schema recorded rowsExamined=131,828, sortRows=31,348, and noIndexUsed=1.
SELECT
o.id,
o.ordered_at,
o.total_cents,
c.id AS customer_id,
c.name AS customer_name
FROM customers AS c
JOIN orders AS o
ON o.customer_id = c.id
WHERE c.country_code = 'KR'
AND o.status = 'PAID'
AND o.ordered_at >= '2025-01-01 00:00:00'
ORDER BY o.ordered_at DESC, o.id DESC
LIMIT 20;
EXPLAIN ANALYZE
-> Limit: 20 row(s) (cost=27404 rows=20) (actual time=46.4..46.5 rows=20 loops=1)
-> Nested loop inner join (cost=27404 rows=13096) (actual time=46.4..46.5 rows=20 loops=1)
-> Sort: o.ordered_at DESC, o.id DESC (cost=13216 rows=130962) (actual time=46.1..46.1 rows=378 loops=1)
-> Filter: ((o.`status` = 'PAID') and (o.ordered_at >= TIMESTAMP'2025-01-01 00:00:00')) (cost=13216 rows=130962) (actual time=15.2..37.8 rows=31348 loops=1)
-> Table scan on o (cost=13216 rows=130962) (actual time=0.214..28.3 rows=131072 loops=1)
-> Filter: (c.country_code = 'KR') (cost=0.25 rows=0.1) (actual time=894e-6..898e-6 rows=0.0529 loops=378)
-> Single-row index lookup on c using PRIMARY (id=o.customer_id) (cost=0.25 rows=1) (actual time=720e-6..747e-6 rows=1 loops=378)