Available inEnglishFrenchGermanHindiPortugueseRussianSpanish
SQL and Databases for Interviews
Write a correct join, GROUP BY or window-function query unaided, then read what the engine did with it: the EXPLAIN plan, the index it picked, the isolation anomaly your transaction is exposed to. For backend engineers facing a database round; SQL syntax is assumed, not taught. Eighty-five cards from join semantics and NULL logic to B-trees, MVCC and isolation levels; replication and sharding belong to System Design Interview.
The second number in cost=0.00..8.30 is blanked. What does that number estimate?
The total cost of returning every row of that node
— It is not milliseconds; the units are the planner's own.
— Ask what the planner minimises when there is no LIMIT.
Source
The cost pair is start-up cost and total cost, both in arbitrary planner units traditionally scaled so that one sequential page fetch costs 1.0 (PostgreSQL manual, Using EXPLAIN). Two consequences worth saying out loud: a cost is comparable only against another plan for the same query, never against a millisecond; and an upper node's cost already includes every child below it, so the top line is the whole query. Commonly confused with the first number, the start-up cost, which the planner weighs heavily instead when a LIMIT means only part of the node's output will be consumed.