Is an index scan always faster than a sequential scan?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn Is an index scan always faster than a sequential scan?
Definition:
An index scan follows an index to locate matching rows, while a sequential scan reads the table directly. If a query needs much of a table, following many scattered row locations can cost more than scanning it. PostgreSQL's planner weighs expected row count, I/O and other costs rather than always preferring indexes.
Key points:
-
No. Reading much of a table may be faster with a sequential scan.
-
Compare estimated rows, actual rows, filters and I/O.
-
An index-only scan also depends on PostgreSQL visibility information, not just covering columns.
-
An index-only scan can still visit the table to check visibility when visibility-map information is insufficient.
Interview point:
- A sequential scan is evidence to understand, not automatically a performance bug.
Adapted from 05_SQL_POSTGRESQL.md · “Is an index scan always faster than a sequential scan?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.