We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
5 system design questions lean on this idea. Each walks through the full answer.
System Design Masterclass · Database Fundamentals
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Database Fundamentals
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
See where this lesson sits in the full path, with real study hours for every stage.
It is easy and good
“It is really nice and good Please join the course”
Soft delete ended at a partial index. Hard delete ended at an index on every foreign key. Both lessons treated the index as the obvious fix and neither said what one actually is, which matters because three of the answers contradict what most people assume.

Two million rows in a real PostgreSQL, with EXPLAIN run on every query, and none of the three findings appears in the model most people carry.
The model most people carry is that an index is a switch which makes a table faster. Every measurement in this lesson is a case where that model gives the wrong answer.

The lab starts a PostgreSQL on a scratch directory, loads two million orders, asks four questions and tears the whole thing down.

At the narrow end the plan is a bitmap heap scan through the index. Past the turn the plan is a parallel sequential scan of the whole table, which is the faster choice.
The flat right-hand end is the part worth carrying. Once the plan is a full scan, selecting 40 percent of a table costs almost exactly what selecting all of it costs, because the work is reading the pages, not deciding about the rows.

An index scan gives you an address. Fetching the row is a separate visit to a page, in index order and not in page order, and that second step is the expensive one.
Forcing the index past the crossover makes the query slower. This is the most common misdiagnosis in query tuning: the plan is not wrong, the expectation about what an index does is.