We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Database Types Storage
Free preview: the first 2 parts of this 7-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 Types Storage
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
When you run INSERT INTO users (name, email, age) VALUES ('Alice', 'alice@email.com', 30), the database needs to physically write those bytes to disk. Here is something most developers never think about: the order in which those bytes are arranged on disk has enormous consequences for performance.
Imagine a library. You could organize books by shelf, each shelf holds one complete book, all pages together. Or you could organize by page number: page 1 of every book on the first shelf, page 2 of every book on the second shelf.
Sounds absurd for a library, right? But databases actually make this choice. Row-oriented storage is the "complete book per shelf" approach. Every column of a single row is stored together, contiguously, on disk.
This is how PostgreSQL, MySQL, Oracle, and Server store data by default. It is the traditional model, and for many workloads, it is exactly right.
In a row-oriented database, each row is stored as a single contiguous block of bytes on disk. When you have a table like this:
| id | name | age | |
|---|---|---|---|
| 1 | Alice | alice@email.com | 30 |
| 2 | Bob | bob@email.com | 25 |
| 3 | Carol | carol@email.com | 35 |
The data on disk looks roughly like this:
[1, "Alice", "alice@email.com", 30] [2, "Bob", "bob@email.com", 25] [3, "Carol", "carol@email.com", 35]
All columns for row 1 are next to each other. All columns for row 2 are next to each other. And so on.
Why does this matter? Because of how disks work. When you read data from disk (especially spinning HDDs, but even SSDs to a degree), reading contiguous bytes is dramatically faster than jumping around. This is called sequential I/O vs random I/O.
So when you fetch a complete row (SELECT * FROM users WHERE id = 1), the database reads one contiguous chunk and has everything it needs. Fast. Efficient. One disk seek.
But when you want just one column across many rows (SELECT AVG(age) FROM users), the database has to read every complete row, extract just the age field, and throw away everything else. It is reading names and emails it does not need, wasting I/O .
It is easy and good
“It is really nice and good Please join the course”