A Route Map Before the Trip: EXPLAIN
Second morning in the engine room. Yesterday's diagram of the frozen report is still hanging on the holo-panel by the hatch—a tree of lines covered in numbers you politely avoided looking at before.
Today you study the navigator's instrument panel and notice something strange: there isn't a single clock on it. Scales, counters, markings—but no seconds anywhere.
QUERY: Good catch. The navigator doesn't carry a clock: when it chooses a route, the trip hasn't started yet, so there's no time to measure. Instead, it estimates the work involved: how many pages to read and how many rows to inspect. The units are arbitrary. The navigator has no real ruler for this work, so cadets call them parrots, after an old cartoon in which a boa constrictor was measured in parrots because there was no meter stick. A parrot can't be converted to seconds or bytes; it is useful only for comparing one route with another. From here on, when this course says “parrots,” it means arbitrary units of
cost.
Open any plan and look at the first reading that stands out: cost. We'll start there.

A node's readout: three instrument readings
A plan is a tree of nodes, and every node follows the same readout format:
Node (cost=start..total rows=estimate width=bytes)
cost=start..total— the node's price in arbitrary units, shown as TWO numbers. Startup is how much work is needed before the first row can be returned. Total is how much work is needed before the last row can be returned. You'll see why both matter in a few minutes, when the diagram gains a node whose two values are almost the same.rows— how many rows the node is expected to send upward. This is an estimate, not a measured result: the query hasn't run.width— the average width of one such row in bytes.rows × widthtells you how much data will flow upward through the tree.
The main thing to remember about cost is this: it's parrots, not milliseconds. The unit represents estimated work rather than time. The planner assigns a price to actions such as reading a page or checking a row, then adds those prices together. It uses the result to compare routes WITH EACH OTHER and choose the cheapest one. You can't convert parrots into seconds: the same cost can correspond to different execution times on different hardware.
You read the tree from top to bottom, but it executes from bottom to top—you already know that from the Vault. The lower levels read tables, while the upper levels work on rows that have already been retrieved. The second diagram will show what their instruments report.
Open the readout for the simplest route—a filter over the log:
Reading the instruments
cost=0.00..3763.00. Startup is zero: a sequential scan can return the first matching row immediately because it has nothing to accumulate first. Total is 3763 parrots for the entire log. We'll break down where that price comes from in a couple of lessons, when we open the I/O map. For now, treat it as the route's price tag.
Filter on the line below. The filter is not a separate node: the scan reads all 180,000 rows in sequence and sends only the warn rows onward. So rows does not mean “how many it reads”; it means “how many it sends upward.”
rows. The diagram shows a little over three thousand. Run the cell again and the number will almost certainly change: it varies from run to run. That's expected. The planner didn't recount the warn rows; it consulted statistics, which are a sampled census of the archive. The sandbox rebuilds both the log and that census on every run, sampling slightly different rows each time. In reality, the log contains exactly 3600 warn readings. The estimate is off by a couple of hundred rows, which is easily accurate enough for choosing a route.
width=21. The average result row is 21 bytes: exactly the four columns you requested. Ask for SELECT *, and width will increase, so more bytes will flow upward through the tree.
QUERY: The rows estimate is the most important reading on the whole panel. As long as it's accurate, the navigator chooses good routes. When it is wrong, you start seeing forty-second queries. Remember this pair: estimate and actual. We'll come back to it.
Now make the navigator bring in a second mechanism: request the same list, but ordered by value.
The tree grows
ORDER BY didn't change the scan route: it still has the same 0.00..3763.00 cost and the same width=21. The rows estimate is slightly different again, but that's the same shifting census you saw in the previous cell, not an effect of ORDER BY. What changed is the new level above the scan: Sort, with an -> arrow before its child scan. Read from the top, it says, in effect, “sort whatever the scan returns.” Execution still starts at the bottom: the scan retrieves the warn rows, then Sort puts them in order.
Now look at Sort's cost pair. This is where the reason for having two numbers becomes clear. The first value is almost equal to the second: nearly four thousand parrots of work must happen BEFORE the first row can be returned. A sort can't send even one row upward until it has consumed all of them, because the final row from the scan might turn out to be the smallest. A scan behaves like a stream: rows flow immediately. Sort behaves like a dam: it holds them back. The start..total pair tells you which kind of node you're looking at.
One more useful reading habit: a node's cost includes the cost of its children. Of Sort's roughly four thousand parrots, most—3763—come from the scan below it. The sorting itself adds relatively little work: three and a half thousand rows is not much for a sort.
You can now read the route map. But remember: the machine still hasn't actually read a single page of the log. Everything here is the navigator's estimate. In the next lesson, we'll send the query on a real trip with EXPLAIN ANALYZE, and a stopwatch will appear on the instrument panel for the first time: we'll compare the estimate with what actually happened.
Seq Scan on ls_readings (cost=0.00..3763.00 rows=3540 width=21). What does the second number in the cost pair—3763.00—mean?cost=0.00..3763.00 and declares, “3763 means the query takes about 3.7 seconds.” Is that correct?
EXPLAIN SELECT reading_id, sensor_id, value, status FROM ls_readings WHERE status = 'warn';