What you'll learn: By the end of this lesson you will be able to read a PostgreSQL plan as a tree, explain where its cost numbers come from, tell the main scan and join nodes apart, compare estimated rows with actual rows to find the node where the planner went wrong, say why stale or independence-assuming statistics cause that, run
EXPLAIN ANALYZEon a write without changing data, and use a runnable PGlite lab that prints every plan the lesson discusses.
Picture a delivery app that plans a route from a map it downloaded last year. The route preview shows what the app expects: 12 minutes, three turns. A dashcam recording of the drive shows what happened: 40 minutes, because a road was closed. Neither is the whole story. The preview explains why the app chose this road; the recording shows whether the map was wrong. A database does the same with your SQL. EXPLAIN is the preview, EXPLAIN ANALYZE adds the recording, and the skill this lesson teaches is putting the two side by side.
Database basics and the B-tree indexes lesson in this module explain what an index is. This lesson shows how to find out whether PostgreSQL used it, why, and what to change.
Verified with the PostgreSQL 18 documentation and PGlite 0.6.1 (a WebAssembly build that reports PostgreSQL 19.0), on 2026-12-01.
The core idea
A query plan is a tree of nodes. The planner builds candidate trees, estimates a cost for each from table statistics, and runs the cheapest one. EXPLAIN prints the chosen tree with its estimates; EXPLAIN ANALYZE also runs the statement and prints what each node really did. When the estimated rows and the actual rows of a node disagree by a large factor, the plan above that node was chosen on bad information, and that is where to look first.
Three illustrations run through the lesson, each labelled:
- Minimal example: one
orderstable, a query byshopper_id, with and without an index (the lab). - Realistic example: ShopStream's "my orders" page after a bulk import, in "In practice".
- Failure example: statistics that no longer describe the data, so the planner is confident and wrong.
What the planner does
The planner sits between the parsed SQL and the executor. For each way it can produce the same rows (scan the heap, use an index, join in a different order) it estimates a cost and keeps the cheapest. The estimates come mainly from statistics kept in the catalogs, not from reading the data while planning.
Figure 1. From SQL to rows. How to read this: the planner's picture of your data comes from the statistics box. EXPLAIN prints what the planner decided; EXPLAIN ANALYZE also counts what the executor then did at each node, which is how a wrong estimate becomes visible.
Cost is a planner unit, not time
The documentation says plainly that "the costs are measured in arbitrary units determined by the planner's cost parameters". Two numbers appear for each node, cost=startup..total. Startup cost is "the time expended before the output phase can begin", for example sorting inside a Sort node; total cost assumes the node "is run to completion". The cost of an upper node includes the cost of all its children.
For a sequential scan the cost is simple arithmetic. The documentation gives the formula as pages read times seq_page_cost plus rows scanned times cpu_tuple_cost, with defaults 1.0 and 0.01, and notes that a WHERE filter adds cpu_operator_cost (default 0.0025) per row. The lab's orders table has 148 pages and 20,000 rows according to pg_class, so a filtered scan costs 148 x 1.0 + 20,000 x 0.01 + 20,000 x 0.0025 = 398. The lab prints exactly cost=0.00..398.00 for that query. That agreement is the point: the cost is not mysterious, it is catalogue numbers times configurable constants.
Because the constants are the planner's guesses about hardware, a cost of 398 does not mean 398 milliseconds. The documentation adds that actual times are in milliseconds "whereas the cost estimates are expressed in arbitrary units; so they are unlikely to match up". Compare costs with costs and times with times.
Rows and width
rows= is "the number emitted by the node", not the number scanned. A sequential scan with a filter may read 20,000 rows and emit 10, and its rows= is 10. width= is the estimated average row width in bytes. When you add ANALYZE, each node gains (actual rows=... loops=...), and these are the numbers to compare with the estimate.
Reading one node
Take the first plan in the lab:
Seq Scan on orders (cost=0.00..398.00 rows=10 width=29) (actual rows=10.00 loops=1)
Filter: (shopper_id = 42)
Rows Removed by Filter: 19990
| Part | Meaning |
|---|---|
Seq Scan on orders |
the node type and the relation it reads |
cost=0.00..398.00 |
startup and total cost, planner units |
rows=10 |
the planner's estimate of rows the node emits |
actual rows=10.00 |
rows the node really emitted, averaged per execution in this build's two-decimal format |
loops=1 |
how many times the node ran |
Filter |
a condition checked on every scanned row |
Rows Removed by Filter: 19990 |
rows scanned and rejected; the line appears only when at least one row was rejected |
The loops field matters inside joins. The documentation says that when a node runs more than once, "the actual time and rows values shown are averages per-execution", so you "multiply by the loops value" to get the total. A node showing actual rows=1.00 loops=5 produced 5 rows in total.
Scan nodes
Four scan shapes cover most plans.
| Node | What it does | The planner tends to choose it when |
|---|---|---|
Seq Scan |
reads every page of the table in order | a large share of the table matches, or the table is tiny |
Index Scan |
walks an index, fetches each matching row from the heap | few rows match, or the order of the index is wanted |
Bitmap Index Scan plus Bitmap Heap Scan |
collects matching row locations, sorts them into physical order, then reads the heap | a moderate number of rows match |
Index Only Scan |
answers from the index alone | every referenced column is in the index and the pages are marked all-visible |
The documentation puts the trade-off between the first two in one sentence: fetching rows separately "is much more expensive than reading them sequentially, but because not all the pages of the table have to be visited, this is still cheaper than a sequential scan". The bitmap node exists because "the upper plan node sorts the row locations identified by the index into physical order before reading them, to minimize the cost of separate fetches".
An index-only scan has a catch that the plan itself reports. PostgreSQL tracks per heap page whether all rows are old enough to be visible to every transaction, in the visibility map. For each index entry the scan checks that bit; if it is not set, "the heap entry must be visited to find out whether it's visible". The Heap Fetches line counts those visits. The documentation says this is the case "if the table row has been modified recently". In the lab, the count is 0 right after VACUUM and non-zero after an update (the exact value is in the captured output below).
The documentation notes that on a table that fits in one disk page you will nearly always get a sequential scan whether indexes exist or not. A sequential scan is not a bug.
Join nodes and loops
Three join algorithms appear in plans.
- Nested Loop: "will run its second, or 'inner' child once for each row obtained from the outer child". Cheap when the outer side is small and the inner side has an index.
- Hash Join: "rows of one table are entered into an in-memory hash table, after which the other table is scanned and the hash table is probed for matches to each row".
- Merge Join: "requires its input data to be sorted on the join keys".
actual rows=5, loops=1"] O["Index Scan on orders
actual rows=5, loops=1
(outer)"] I["Index Scan on shoppers
actual rows=1, loops=5
(inner)"] NL --> O NL --> I
Figure 2. A nested loop as a tree. How to read this: read the tree from the leaves up. The outer scan runs once and yields 5 rows; the inner scan runs once per outer row, so its loops is 5. Multiply actual rows=1 by loops=5 for the inner node's total.
Which side becomes the outer side is part of the plan, so read it from the plan rather than from the order you wrote the tables. Join semantics belong to the SQL joins lesson in this module; here the point is only how to recognise each shape.
Estimates versus actual rows
Everything above explains how to read a plan. Diagnosing a slow one starts from a single comparison: for each node, is rows= (estimate) close to actual rows=?
Figure 3. Estimated versus actual rows as the first test. How to read this: a close match means the planner had good information, so its choice is probably sensible given the schema. A large gap sends you to the statistics before you touch indexes or hints. "Far apart" is a judgement; a factor of ten or more deserves attention, and the lab shows gaps of 5 and 29.
Where estimates come from
To estimate rows the planner needs the table size and the fraction of rows each condition keeps, called selectivity. The table size comes from pg_class (relpages, reltuples), which "are not updated on-the-fly" and "are updated by VACUUM, ANALYZE, and a few DDL commands such as CREATE INDEX". Selectivity comes from pg_statistic, readable through the pg_stats view: most common values, a histogram of the rest, and more. The default limit on entries per column is 100, set by default_statistics_target.
Failure 1: correlated columns
The planner "normally assumes that multiple conditions are independent of each other, an assumption that does not hold when column values are correlated". In the lab, region is computed from store_id, so store_id = 7 and region = 0 matches exactly the rows of store 7. With single-column statistics only, the planner multiplies the two selectivities and estimates 80 rows; the real answer is 400. The fix is extended statistics: CREATE STATISTICS ... (dependencies) ON store_id, region FROM orders followed by ANALYZE. The documentation defines a functional dependency as column b being determined by column a, and says that with such statistics "the planner recognizes that the WHERE conditions are redundant and does not underestimate the row count". The documentation's examples run ANALYZE right after CREATE STATISTICS, and so does the lab.
Failure 2: stale statistics
The lab then inserts 8,000 more rows, all with status placed, without running ANALYZE. The planner still believes placed is about 1 percent of the table and estimates 278 rows; 8,200 come back. After ANALYZE the estimate is 8,200. Note what did not change: the plan shape stayed an Index Scan. A wrong estimate does not always change the plan, but when it does (a nested loop chosen for a far larger outer side than expected, for example) the query can become far slower. The documentation says the planner statistics must be up to date and that autovacuum normally takes care of it, so a table that changes in bulk (an import, a purge) is the place to run ANALYZE yourself.
Running EXPLAIN ANALYZE safely
EXPLAIN alone never runs the statement. EXPLAIN ANALYZE does: "the statement is actually executed when the ANALYZE option is used". For a SELECT the output rows are discarded; for anything else the side effects happen. The documented way to look at a write without keeping it is a transaction you roll back.
Figure 4. A safe EXPLAIN ANALYZE on a write. How to read this: the rows are changed inside the transaction while the plan is measured, then thrown away by the rollback. Locks the UPDATE took are held until the rollback, so keep the transaction short on a busy table.
Three more facts to carry into production:
- Timing has a cost. The documentation warns that the profiling overhead "can be significant, especially on machines with slow gettimeofday() operating-system calls".
TIMING FALSEkeeps the row counts (which are all you need to compare with estimates) and drops the per-node clock. - Buffers come with ANALYZE. "Buffers information is automatically included when ANALYZE is used" (PostgreSQL 18 documentation); it counts pages hit, read, dirtied and written.
- The plan is not the whole latency. The plan cost "does not consider the time spent to convert output values to text form or to transmit them to the client".
Trade-offs: what to change when a plan is bad
| Option | Gain | Cost | Wrong when |
|---|---|---|---|
ANALYZE the table |
fixes estimates after bulk change | reads a sample, brief extra work | the estimate was fine and the query shape is the problem |
CREATE STATISTICS on correlated columns |
fixes row estimates for combined filters | more work at ANALYZE, one more object to maintain |
the columns are independent |
| Add an index | turns a scan of many rows into a lookup | slower writes, more storage | most rows match anyway, so the planner will ignore it (lab step 3) |
Covering index with INCLUDE |
enables index-only scans | larger index | the table is written constantly, so pages are rarely all-visible |
Raise default_statistics_target or a column's target |
better histograms for skewed data | longer ANALYZE |
the gap comes from correlation, not detail |
| Rewrite the query | removes work the planner cannot avoid | engineering time, risk of changed meaning | the data is simply large |
enable_* settings |
shows the plan the planner rejected | a session-wide distortion | it is used as a fix instead of a probe |
The documentation describes the enable_* flags as a way "to look at variant plans" and notes that many only discourage a node type. Use them in a session to learn what the alternative costs, then fix the cause.
Build it: read the plans yourself
This is the minimal example, a lab you can run. It uses PGlite, which is real PostgreSQL compiled to WebAssembly running in-process, so the planner, executor and EXPLAIN output are PostgreSQL's own. The build reports PostgreSQL 19.0 (PGlite 0.6.1); the links in this lesson are the PostgreSQL 18 documentation, the course's target version, and any output detail you rely on in production should be checked against your own server. PGlite is a single in-memory connection, so the lab says nothing about concurrency, disk behaviour or server configuration.
Goal. Watch a plan change when an index appears, see the planner ignore an index, and watch two estimate failures and their fixes.
Setup. From examples/postgres-labs (after npm install once):
node --test labs/query-plans/test.mjs
cd labs/query-plans && node run.mjs
The first command runs 10 assertions. The data is generated and illustrative: 20,000 orders, 2,000 shoppers. The code is in examples/postgres-labs/labs/query-plans/.
Steps 1 and 2: without and with an index. The first query has no index on shopper_id.
Expected output, captured from a real run (PGlite 0.6.1, PostgreSQL 19.0 build, 2026-12-01):
## 1. No index on shopper_id: a sequential scan reads every row and throws most away
> select * from orders where shopper_id = 42
Seq Scan on orders (cost=0.00..398.00 rows=10 width=29) (actual rows=10.00 loops=1)
Filter: (shopper_id = 42)
Rows Removed by Filter: 19990
## 2. Add an index and re-analyze: the same query now reads about ten rows
> select * from orders where shopper_id = 42
Bitmap Heap Scan on orders (cost=4.37..36.69 rows=10 width=29) (actual rows=10.00 loops=1)
Recheck Cond: (shopper_id = 42)
Heap Blocks: exact=10
-> Bitmap Index Scan on orders_shopper_idx (cost=0.00..4.36 rows=10 width=0) (actual rows=10.00 loops=1)
Index Cond: (shopper_id = 42)
Index Searches: 1
Read the first plan: 20,000 rows scanned, 19,990 removed, 10 emitted, cost 398 (the arithmetic above). After create index and analyze, the planner picks a bitmap scan with an estimated total cost of 36.69, a tenth of the sequential cost, and the estimate (10) equals the actual count (10).
Steps 3 and 4: when the index is ignored. Status delivered matches 99 percent of the table.
Expected output, captured from a real run (same build):
## 3. A predicate that matches 99 percent of the table: the planner ignores the index
> select * from orders where status = 'delivered'
Seq Scan on orders (cost=0.00..398.00 rows=19800 width=29) (actual rows=19800.00 loops=1)
Filter: (status = 'delivered'::text)
Rows Removed by Filter: 200
same query with enable_seqscan = off (a diagnostic, never a fix): the rejected plan and its higher estimated cost
> select * from orders where status = 'delivered'
Index Scan using orders_status_idx on orders (cost=0.29..585.99 rows=19800 width=29) (actual rows=19800.00 loops=1)
Index Cond: (status = 'delivered'::text)
Index Searches: 1
## 4. The rare value (1 percent): the index wins
> select * from orders where status = 'placed'
Index Scan using orders_status_idx on orders (cost=0.29..31.27 rows=200 width=29) (actual rows=200.00 loops=1)
Index Cond: (status = 'placed'::text)
Index Searches: 1
The planner keeps the sequential scan at cost 398.00 and rejects the index. With enable_seqscan = off it shows the plan it threw away: an index scan whose estimated total is 585.99. The rare value placed (1 percent) gets the index.
Steps 5 and 6: join shapes. Cost numbers are hidden here so the tree stays readable.
Expected output, captured from a real run (same build):
## 5. Join shapes: a nested loop probes the inner side once per outer row (see loops=5)
> select s.name, o.total_cents from orders o join shoppers s on s.id = o.shopper_id where o.id <= 5
Nested Loop (actual rows=5.00 loops=1)
-> Index Scan using orders_pkey on orders o (actual rows=5.00 loops=1)
Index Cond: (id <= 5)
Index Searches: 1
-> Index Scan using shoppers_pkey on shoppers s (actual rows=1.00 loops=5)
Index Cond: (id = o.shopper_id)
Index Searches: 5
## 6. Join shapes: many outer rows, so one hash table is built instead
> select s.name, o.id from orders o join shoppers s on s.id = o.shopper_id where o.store_id = 7
Hash Join (actual rows=400.00 loops=1)
Hash Cond: (o.shopper_id = s.id)
-> Seq Scan on orders o (actual rows=400.00 loops=1)
Filter: (store_id = 7)
Rows Removed by Filter: 19600
-> Hash (actual rows=2000.00 loops=1)
Buckets: 2048 Batches: 1 Memory Usage: 91kB
-> Seq Scan on shoppers s (actual rows=2000.00 loops=1)
The nested loop's inner node shows loops=5 and Index Searches: 5, one lookup per outer row. When 400 outer rows qualify, the planner builds one hash table of the 2,000 shoppers instead.
Steps 7 and 8: estimates that are wrong.
Expected output, captured from a real run (same build):
## 7. Estimates: two correlated columns, estimated as if independent
> select * from orders where store_id = 7 and region = 0
Seq Scan on orders (cost=0.00..448.00 rows=80 width=29) (actual rows=400.00 loops=1)
Filter: ((store_id = 7) AND (region = 0))
Rows Removed by Filter: 19600
create statistics (dependencies) on store_id, region; analyze orders
> select * from orders where store_id = 7 and region = 0
Seq Scan on orders (cost=0.00..448.00 rows=400 width=29) (actual rows=400.00 loops=1)
Filter: ((store_id = 7) AND (region = 0))
Rows Removed by Filter: 19600
## 8. Estimates: statistics that are out of date
after inserting 8,000 more 'placed' orders and no ANALYZE:
> select * from orders where status = 'placed'
Index Scan using orders_status_idx on orders (cost=0.29..40.76 rows=278 width=29) (actual rows=8200.00 loops=1)
Index Cond: (status = 'placed'::text)
Index Searches: 1
after ANALYZE orders:
> select * from orders where status = 'placed'
Index Scan using orders_status_idx on orders (cost=0.29..250.63 rows=8200 width=29) (actual rows=8200.00 loops=1)
Index Cond: (status = 'placed'::text)
Index Searches: 1
The correlated predicate is estimated at 80 rows and returns 400, and the estimate is exactly 400 after create statistics and analyze. After 8,000 bulk-inserted rows, the stale estimate is 278 against 8,200 actual; analyze brings it to 8,200.
Steps 9 and 10: index-only scans and a safe write analysis.
Expected output, captured from a real run (same build):
## 9. Index-only scans and Heap Fetches
after VACUUM orders:
> select shopper_id from orders where shopper_id between 10 and 12
Index Only Scan using orders_shopper_idx on orders (actual rows=42.00 loops=1)
Index Cond: ((shopper_id >= 10) AND (shopper_id <= 12))
Heap Fetches: 0
Index Searches: 1
after updating the matching rows:
> select shopper_id from orders where shopper_id between 10 and 12
Index Only Scan using orders_shopper_idx on orders (actual rows=42.00 loops=1)
Index Cond: ((shopper_id >= 10) AND (shopper_id <= 12))
Heap Fetches: 69
Index Searches: 1
## 10. EXPLAIN ANALYZE runs the statement: wrap a write in a transaction and roll it back
> update orders set status = 'cancelled' where shopper_id = 42
Update on orders (actual rows=0.00 loops=1)
-> Bitmap Heap Scan on orders (actual rows=14.00 loops=1)
Recheck Cond: (shopper_id = 42)
Heap Blocks: exact=14
-> Bitmap Index Scan on orders_shopper_idx (actual rows=14.00 loops=1)
Index Cond: (shopper_id = 42)
Index Searches: 1
orders with status 'cancelled' after ROLLBACK: 0
Heap Fetches goes from 0 after VACUUM to a non-zero count once rows are updated. Step 10 shows the UPDATE node of an EXPLAIN ANALYZE run inside begin and rollback: the plan reports 14 rows found, and the count of cancelled orders afterwards is 0.
Step 11: why there are no timings. Time is real but never repeatable, so the golden file holds none; the demo checks only that default output carries the timing lines.
Expected output, captured from a real run (same build):
## 11. Timing is real but never deterministic, so this lab hides it
default ANALYZE output has per-node 'actual time=': true
default ANALYZE output ends with 'Planning Time' and 'Execution Time' lines: true
Break it. In run.mjs, remove the analyze orders line that follows the bulk insert in step 8: the estimate stays at 278. Put it back and rerun the tests.
In practice: ShopStream's order history after a bulk import
This is the realistic example, an educational scenario on ShopStream, the course's running grocery marketplace. Every number is illustrative.
This is a realistic scenario, not a case history.
The situation
The "my orders" page lists a shopper's last 20 orders. It has been fast for months. The team backfills several million archived orders from an older system into the orders table in one overnight job. The next morning the page's slowest requests take seconds instead of milliseconds, for a subset of shoppers.
Starting architecture
Figure 5. The read path and the backfill. How to read this: the page reads through one query on the orders table. The backfill adds many rows through a different path, and nothing in it refreshes the planner's statistics.
Options considered
| Option | Effect | Risk |
|---|---|---|
| A. Add another index | might help a symptom | extra write cost on a table just loaded; the cause may be estimates |
| B. Rewrite the query | could remove the slow shape | changes behaviour without understanding the cause |
C. Read the plan, compare estimates with actual rows, then ANALYZE |
targets the cause | needs a safe way to run the slow query |
The decision
Option C. An engineer runs EXPLAIN (ANALYZE, TIMING OFF) on the slow statement for an affected shopper, in a read-only session on a replica copy of the data, and finds a node estimated at a few hundred rows that returns tens of thousands, the same shape as lab step 8. They run ANALYZE orders, re-run the plan and see the estimate match the actual count.
Rollout and verification
The team adds ANALYZE of the affected tables to the end of the backfill job and to the runbook for any future bulk load or purge. Verification is the two numbers from this lesson: estimated and actual rows on the page's query for a sample of shoppers, checked after each load, and the page's latency percentile for the slow subset.
The 2 a.m. failure
Weeks later the page alerts again for a different shopper segment, and ANALYZE does not fix it. The plan's estimates are now close for the first node but far off for a filter on two columns, a store and a region, that always move together. This is lab step 7. The fix is CREATE STATISTICS ... (dependencies) on those columns followed by ANALYZE, and the lesson for the runbook is to add the question "are two filtered columns correlated?" next to "is the table freshly analyzed?".
Architect's notes
- Always compare both numbers. A plan with only estimates tells you what the planner believed. Estimates plus actuals tell you whether it was right.
- Fix statistics before adding indexes. An index cannot repair a wrong row estimate, and each index slows every write.
- Keep
enable_*as a probe. Use it to see the alternative plan's cost, then remove it. - Name the version. The
Index Searchesline and fractionalactual rowsvalues in the captured output come from the PostgreSQL 19.0 build in PGlite; check your server's output format.
Common mistakes
- Reading
costas time. It is in planner units. - Ignoring
loops. A node withactual rows=1 loops=100000did the work of 100,000 lookups. - Running
EXPLAIN ANALYZEon a write without a transaction. The write happens. - Concluding "the index is ignored, so it is broken". When most rows match, the planner is right to scan.
- Blaming indexes for a statistics problem. Check estimated versus actual rows first.
- Setting
enable_seqscan = offglobally. It distorts every query in the session.
Key takeaways
- A plan is a tree of nodes;
EXPLAINshows estimates andEXPLAIN ANALYZEadds what actually happened. - Cost is an estimate in planner units built from catalogue numbers and cost constants, not milliseconds.
rowsis what a node emits;loopsmultiplies the per-execution averages.- Seq, index, bitmap and index-only scans differ in how much of the table they touch; the planner picks by estimated cost, so broad predicates keep sequential scans.
- A large gap between estimated and actual rows points at statistics: stale (
ANALYZE), correlated columns (CREATE STATISTICS) or skew. EXPLAIN ANALYZEruns the statement; wrap writes inBEGINandROLLBACK.
Practice exercises
Exercise 1 (20 min). Using the formula in the lesson, compute the sequential scan cost of a table with 500 pages and 40,000 rows, with and without one filter. Then check your arithmetic against the lab by changing the row count in plans.mjs.
Exercise 2 (45 min). In the lab, add a composite index on (store_id, region) and rerun step 7. Explain why the estimate stays at 80 or changes, and what the index does and does not fix.
Exercise 3 (1 hour). Extend step 8 so the bulk insert is 60 percent placed rather than 29 percent. Does the plan shape change after ANALYZE? Write what you saw and why the answer depends on the data.
Exercise 4 (2 hours). For ShopStream's "last 20 orders" query, write the index you would create, predict the plan node, then verify with the lab pattern.
Related reading
- Databases basics: what tables, indexes and transactions are.
- Storage engines: how pages and indexes are laid out on disk.
- ShopStream Stage 3: the data model: the relational core these queries run against.
- SQL versus NoSQL decision framework: when relational planning is the right tool.
- Later lessons in this module (named here as plain text): B-tree indexes and SQL indexing, SQL joins, MVCC, table partitioning, and the lesson on JPA and Hibernate N+1 queries.
Official documentation
- PostgreSQL 18, Using EXPLAIN: plan nodes, costs,
ANALYZE, loops, caveats. - PostgreSQL 18, EXPLAIN: options and the warning that
ANALYZEexecutes the statement. - PostgreSQL 18, Statistics used by the planner:
pg_class,pg_stats, extended statistics. - PostgreSQL 18, CREATE STATISTICS: kinds and syntax.
- PostgreSQL 18, Planner cost constants and enable flags.
- PostgreSQL 18, Index-only scans and covering indexes.