A sequential scan, also called a full table scan or table scan, is a database access method that reads every page of a table in physical storage order and evaluates the query conditions against each row. In databases and in the topic of indexing, it is the baseline access path that the query planner chooses when no usable index exists or when an index would be slower than reading the whole table.
A sequential scan is not inherently a performance problem. Because it reads data in large contiguous blocks, it is often the cheapest plan for small tables and for queries that return a large fraction of the rows.
How a sequential scan reads a table
A sequential scan works by iterating over the table’s heap pages from the first to the last, loading each page into the buffer cache and checking every tuple on it against the filter predicate. Rows that satisfy the condition are passed to the next plan node, such as a sort, an aggregate or a join. Unlike an index scan, it does not consult any auxiliary structure, so its cost depends almost entirely on table size, not on the selectivity of the condition.
Storage engines optimize this access pattern aggressively. Operating systems and database engines apply read-ahead prefetching, which issues large sequential reads before the pages are needed. PostgreSQL also uses a small ring buffer for scans of large tables so that one big scan does not evict the entire shared cache, and it can run parallel sequential scans in which several worker processes divide the pages between them.
| Stage | What happens | Main cost factor |
|---|---|---|
| Page fetch | Next block read from cache or disk | I/O throughput |
| Visibility check | Tuple checked against the transaction snapshot | Dead tuple count |
| Predicate evaluation | WHERE condition tested on each row | CPU per row |
| Row output | Qualifying rows passed upward | Number of matches |
Why the query planner chooses a sequential scan
The query planner chooses a sequential scan when its cost model estimates that reading the whole table is cheaper than any index-based alternative. The decision rests on table statistics, the estimated selectivity of the predicate and configured cost constants. In PostgreSQL, seq_page_cost defaults to 1.0 and random_page_cost to 4.0, which expresses the assumption that random reads are about four times more expensive than sequential ones.
As a rough rule, an index becomes unattractive once a query returns more than roughly 5-20% of the rows, although the real threshold depends on row width, physical correlation between index order and table order, cache contents and storage type. On SSDs the gap between random and sequential reads is smaller, so administrators often lower random_page_cost toward 1.1-2.0, which makes index scans win more often.
| Situation | Why a sequential scan is chosen | Is it a problem |
|---|---|---|
| Small table | A few pages are read faster than an index lookup | No |
| Low selectivity | Most rows qualify anyway | No |
| Missing index | No access path matches the predicate | Often yes |
| Non-sargable predicate | Function or cast on the column blocks the index | Usually yes |
| Stale statistics | Planner misjudges row counts | Yes |
Sequential scan compared with index-based access
A sequential scan differs from index-based access in its I/O pattern: it reads every page once and in order, whereas an index scan follows a B-tree index to individual rows and may visit table pages in random order. A bitmap heap scan sits between the two, collecting matching row locations first and then reading the needed pages in physical order. An index-only scan avoids the table entirely when the index covers all requested columns.
| Access method | Pages read | Best when | Weakness |
|---|---|---|---|
| Sequential scan | All table pages | Large share of rows needed | Cost grows with table size |
| Index scan | Index plus matching table pages | Few rows, high selectivity | Random I/O per row |
| Bitmap heap scan | Index plus sorted table pages | Moderate selectivity | Bitmap build overhead |
| Index-only scan | Index pages, visibility map | Covering index available | Needs up-to-date visibility map |
Specialized structures change the trade-off for some workloads. A BRIN index can skip whole block ranges in very large, naturally ordered tables, and columnar storage reduces the bytes a scan must read by loading only referenced columns.
Diagnosing and tuning sequential scans
Sequential scans are diagnosed by reading the execution plan, for example with EXPLAIN ANALYZE in PostgreSQL or EXPLAIN in MySQL, where InnoDB reports the access type ALL for a full table scan. The useful question is not whether a scan appears, but whether estimated and actual row counts agree and whether the scan dominates execution time. Monitoring views such as pg_stat_user_tables show how often each table is scanned sequentially.
| Symptom | Likely cause | Typical fix |
|---|---|---|
| Slow lookup by one key | No index on the filter column | Create a suitable index |
| Index ignored for lower(email) | Function applied to the column | Add an expression index |
| Scan after bulk load | Outdated statistics | Run ANALYZE |
| Scan reads far more pages than rows justify | Table bloat from dead tuples | VACUUM or rebuild the table |
| Mismatched types in join | Implicit cast prevents index use | Align column data types |
Disabling sequential scans globally, for instance with enable_seqscan = off, is a diagnostic tool only. It forces the planner away from the scan to compare plans, but leaving it off in production usually degrades other queries that genuinely benefit from a full read.
Common misconceptions about full table scans
- Every sequential scan is a defect: analytical queries and small lookup tables are often best served by one.
- Adding an index always removes the scan: if the predicate matches most rows, the planner still prefers a full read.
- LIMIT makes a scan cheap: it stops early only when matching rows appear near the start of the table.
- A scan reads only live data: in MVCC databases it also reads dead row versions until vacuuming removes them.
The practical guidance is to treat a sequential scan as a signal to verify, not an automatic alarm. When it appears on a large table in a frequent, selective query, it deserves investigation; elsewhere it is usually the correct plan.
Stripped to the essentials
A sequential scan means the database reads a table from start to finish, row by row, to find what a query asks for. It is like looking for a name in an unsorted stack of papers by checking every sheet.
That sounds slow, and for one name in a huge stack it is. But when you need half of the papers anyway, flipping through the whole stack is faster than jumping around with an index. The key point is that a full read is sometimes the smartest choice, and the database decides this by estimating costs.
Where it is applied
An online store runs PostgreSQL with an orders table of about 40 million rows. Customer support reports that searching orders by email takes around 9 seconds. The execution plan shows a sequential scan on orders reading roughly 5 GB, because the query filters on lower(customer_email) and the only index covers the raw column.
The database engineer creates an expression index on lower(customer_email) and refreshes statistics. The same lookup now uses an index scan and finishes in under 5 milliseconds. At the same time, the nightly revenue report, which aggregates all orders of the past year, keeps its sequential scan, because it needs most of the table and runs faster as a full read.