Dataseq scanfull table scantable scan

Sequential scan

Definition

A sequential scan is a query plan step that reads a table from start to end and filters each row, with cost proportional to the size of the table.

In practice

On a selective filter over a large table, a sequential scan is the usual sign of a missing index: EXPLAIN ANALYZE shows Seq Scan with Rows Removed by Filter in the millions. A common cause is a foreign key column without an index, which also makes joins and cascading deletes slow.

Scans are not always wrong. For small tables, or filters that match a large share of rows, reading pages sequentially is cheaper than millions of random index lookups, and the planner chooses it on purpose. Scans also get worse silently as the table grows, so a query that was fine at launch can time out a year later.

Example

EXPLAIN ANALYZE SELECT * FROM comments WHERE post_id = 7 shows Seq Scan on comments ... Rows Removed by Filter: 4999980 taking 900 ms until an index on post_id is added.