We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
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
It is easy and good
“It is really nice and good Please join the course”
A view is a rewrite the planner can see through. A function is code, and how much the planner can see through it depends on two things the author chose: the volatility category and the language.
Both are one word, both are usually left at the default, and both change the plan by orders of magnitude.

A real PostgreSQL, a million rows, and one function written three times with only the volatility keyword changed.
The volatility category is a promise the author makes to the planner about whether the same arguments always give the same answer. The planner believes it completely, and everything about how many times the function runs follows from it.

Every timing is the execution time reported by EXPLAIN ANALYZE against a database this lab started and tore down.

To use an index the planner must know what it is looking for before it starts. A function that may return something different on every call cannot supply that.

Which means the tall bar is what you get by not saying anything. Most functions in most schemas are declared without a category, and most of them would be correct as STABLE or IMMUTABLE.
Declare the category on every function you write, and declare it honestly. It costs one word, it is the single largest lever in this lesson, and leaving it out chooses the most pessimistic option available.