An index on date.0 pages read · 0 rows read
Chapter 5 of 7
When the planner skips your index
The team adds an index on date for the warehouse’s reports. Today’s orders come back fast; this month’s report is no faster.
This chapter: Why would the database ignore an index you built?
About this chapter
You will learn
- The planner guesses each way’s cost first
- An index fetches its rows one by one
- Past a small share of rows, a scan wins
Words you’ll meet
- Planner
- The part of the database that picks how to run each request, before running it.
- Estimated rows
- The planner’s guess of how many rows a request matches, from statistics it keeps.
Step 1 of 5
Before each request the guesses every way’s page reads from its , then picks the cheapest.
Ask for today’s orders.
The SQL
CREATE INDEX ON orders (day);
SELECT * FROM orders WHERE day = DATE '2026-01-01' + 296;
SELECT * FROM orders
WHERE day BETWEEN DATE '2026-01-01' + 273 AND DATE '2026-01-01' + 296;