advancedPerformance — EXPLAIN ANALYZE, Partitioning & Sharding
A query on a 500-million-row orders table takes 45 seconds. EXPLAIN shows a Seq Scan. How do you fix it?
Step-by-step: 1) Identify the WHERE clause filter columns: WHERE order_date >= '2024-01-01' AND status = 'PENDING'. 2) Create targeted index: CREATE INDEX CONCURRENTLY ON orders(order_date, status) WHERE status IN ('PENDING', 'PROCESSING'). Partial composite index. 3) EXPLAIN ANALYZE again — should show Index Scan or Bitmap Index Scan. 4) If still slow: consider partitioning by order_date (RANGE P
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
A query on a 500-million-row orders table takes 45 seconds. EXPLAIN shows a Seq Scan. How do you fix it?