Sequential Scans vs Index Scans
Know when a sequential scan is fine, when an index scan is required, and how the planner decides.
Two Ways to Find Rows
The database has two basic strategies for reading rows:
- Sequential Scan — read every page of the table
- Index Scan — walk an index, fetch matching rows
When Sequential Scan Is Right
If you need most of the table anyway, scanning is cheaper than reading the index AND fetching each matching row. Roughly: over ~10–20% of rows → seq scan wins.
All lessons in this course
- Reading EXPLAIN and EXPLAIN ANALYZE
- Sequential Scans vs Index Scans
- Hash Join vs Merge Join vs Nested Loop
- Identifying and Fixing Slow Queries