Query Optimisation
- Optimise the question. The fastest work is work avoided: filter earlier, select fewer columns, aggregate at the right grain.
- Sargable predicates. A sargable predicate lets an index work: wrapping the column in a function usually blinds it.
- Pagination honestly. Deep OFFSET pagination re-reads everything skipped: keyset pagination seeks straight to the next page.
Index and Schema Trade-Offs
- Covering indexes. A covering index contains every column the query needs: the table itself never gets touched.
- Partial indexes. A partial index covers only rows matching a condition: small, hot and exactly shaped to one query.
- Measuring index value. Engines report index usage: the unused index taxing every write is deleted with confidence, not fear.
Production Database Performance
- Find the heavy hitters. Statement statistics rank queries by total time: tune the top five, ignore the exotic thousand.
- Connection pooling. Databases hate connection churn: a pool reuses warm connections and caps concurrency honestly.
- N+1 from SQL’s side. The N+1 pattern shows as one query repeated hundreds of times per request: fix it with one joined or batched query.
Before and after this level
- Before: Level 13: Warehousing SQL: Dimensional Modelling, Analytical Transformations, Large-Scale SQL Patterns.
- Next: Level 15: SQL Mastery: Reading Complex Query Plans, Correctness Under Concurrency, Designing and Improving Production SQL.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does SQL Level 14: SQL Performance cover?
Query Optimisation, Index and Schema Trade-Offs, Production Database Performance: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 13: Warehousing SQL, which covers Dimensional Modelling, Analytical Transformations, Large-Scale SQL Patterns.