SQL Tutorial & Database Internals: JOINs, Indexes, MVCC
Free visual SQL tutorial: GROUP BY, JOINs, window functions and CTEs, then indexes, transactions, MVCC and locks in MySQL and PostgreSQL, plus interviews.
What you will learn
- WHERE filters rows; HAVING filters groups
- Rows, pages, and what an index actually stores
- SELECT plans: seq scan vs index vs covering
- Transactions, isolation, and lost updates
- Normalization vs the query you have to serve
- Migrations without locking the product
- When Postgres is enough and when it is not
How it works
Broken queries and lost updates first. Then the schema, index, and isolation level that make the same write safe.
Queries: Values, functions and NULL
Queries: GROUP BY and HAVING
- SQL GROUP BY Explained Visually, with Examples
- SQL GROUP BY with SUM, COUNT and AVG: Examples
- SQL GROUP BY with WHERE: Filter Rows Before Grouping
- SQL HAVING Clause Explained with Examples
- HAVING with COUNT and SUM: Filter Groups in SQL
- WHERE vs HAVING in SQL: Difference with Examples
- Invalid Use of Group Function: SQL HAVING Errors Fixed
- Column Not in GROUP BY Clause Error (ONLY_FULL_GROUP_BY)
- SQL Order of Execution: WHERE, GROUP BY, HAVING, LIMIT
- COUNT(*) vs COUNT(column) in SQL: How NULLs Are Counted
- SQL GROUP BY and HAVING Cheat Sheet
Queries: Joins: basics
Queries: Joins: advanced
Queries: Subqueries
Queries: WITH and CTEs
Queries: Window functions
Queries: Practice
Internals: Storage engine
Internals: Indexes: what and why
Internals: Indexes: test yourself first
Internals: Indexes: how they are built
Internals: Indexes: how queries use them
- Why an Index Lookup Is Still Slow: Key Lookups Explained
- Covering Index in SQL Explained with Examples
- Composite Index and the Leftmost Prefix Rule Explained
- Index Range Scan Explained: BETWEEN, > and < on a B-Tree
- ORDER BY and GROUP BY Using an Index (Avoid Filesort)
- B-Tree vs Hash Index: Which to Use and Why
- Why Is MySQL Not Using My Index? Common Reasons
Internals: Indexes: special kinds and practice
Internals: Logs, versions and the buffer pool
- Buffer Pool Explained: Which Database Pages Stay in Memory
- Redo Log Explained: How Databases Make Commits Durable
- Undo Log Explained: Rollback and Old Row Versions
- MVCC Explained: Multi-Version Concurrency Control
- Database Checkpoints Explained: Crash Recovery
- Database Replication Explained: Binlog, WAL and Replicas
Internals: Transactions: ACID
Internals: Transactions: isolation
Internals: Transactions: locks and production
Internals: Life of a statement
Internals: Query execution and the optimizer
- How the Query Optimizer Builds an Execution Plan
- Nested Loop vs Hash Join vs Merge Join Explained
- JOIN vs Correlated Subquery: Which Is Faster?
- Why OFFSET Is Slow in SQL, and How LIMIT Can Stop Early
- Keyset (Cursor) Pagination vs OFFSET in SQL
- SQL Performance Tuning: Common Slow Query Mistakes
- Ten questions before you trust a fast query
Internals: Running a database in production
Internals: Scaling out
Engines: MySQL and InnoDB
- InnoDB storage: clustered pages, change buffer, adaptive hash, doublewrite
- InnoDB redo, the binlog and the two-phase commit between them
- InnoDB read views, undo purge and the history list
- InnoDB Gap Locks and Next-Key Locks Explained
- A primary key is known before execution starts
- MySQL EXPLAIN Explained: const, ref, range, index, ALL
- MySQL settings that change query speed
- MySQL diagnosis: slow log, optimizer trace, performance schema
Engines: PostgreSQL
- PostgreSQL VACUUM and MVCC Explained
- PostgreSQL WAL, full-page writes and checkpoints
- PostgreSQL locks and isolation: snapshots, SSI and no gap locks
- PostgreSQL Index Types: B-Tree, GIN, GiST, BRIN
- PostgreSQL EXPLAIN ANALYZE: How to Read It
- PostgreSQL settings and diagnosis: shared_buffers, work_mem, pg_stat_statements
Build: Build a mini database engine
- The engine you will build, one layer per chapter
- Find row 2 without reading every byte
- TLV: every value says its own type and length
- Insert, select, delete and update on a plain file
- A write-ahead log lets a crashed insert be replayed
- Cut the table file into pages the engine can find
- A B-tree index file turns a key into a file offset
- A small LRU cache saves most disk reads
- A full-text index maps each word to the rows that hold it
- From SQL text to rows: parse, plan and iterators
Case studies: Database design case studies
- Database Design Interview: A 7-Step Framework
- Design the database for a Q&A site like Quora
- Design the database for a short-video app like TikTok
- Design the database for a booking site like Airbnb
- Design the database for an ephemeral messaging app like Snapchat
- Who gets the last phone in a flash sale
- Which database for a food delivery app
- The cache expired and the database fell over
- A live final: scale before the toss
- An app like ChatGPT: the answer is written live
- A product Q&A box on sale day
- Tatkal at 10:00: one seat, sold in stretches
- A group chat: one register, many sockets
Interviews: Interviews: must read — test yourself first
Interviews: Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: rate limit is 2/min, 30 requests get through
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Interview: everything got slow and the disk keeps growing
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: every page view is a read-write query on the leader
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.