B-Tree Height: Why 100 Million Rows Need Only 3–4 Reads

One page holds hundreds of keys, so each level multiplies capacity. Why a B-tree over 100 million rows is only 3 or 4 levels deep.

In this chapter

B-tree height is why 100 million rows still take three reads

More on Indexes: how they are built

Keep learning

Overview

Page size 16 KB by default (innodb_page_size), the unit of every read Internal entry children per internal page: a few hundred to about a thousand for an 8-byte key Leaf capacity whole rows (clustered) or key + primary key (secondary): depends on row size number of levels from root to leaf: grows with the logarithm of the row count Cached levels root and upper levels are tiny and hot, so they live in the buffer pool chapters · indexes B-tree height is why 100 million rows still take three reads Every extra level of a B-tree multiplies how many rows it can hold by hundreds, so the number of levels grows very slowly with table size. This chapter turns that into arithmetic you can do yourself: entries per page, number of levels, which levels stay in memory, and why a wide key or a secondary index changes the answer.

2. The real cost is the leaf, not the height

Height counts page visits, not disk reads. The root is one page. The level under it is a few hundred pages, the next one a few hundred thousand at most. Those upper levels together are small (a few megabytes to a few hundred), and every lookup passes through them, so they are the hottest pages in the buffer pool (see the buffer pool). The leaf level is the bulk of the data and is the one that can miss.

3. Wide keys, text keys, and UUIDs

Fan-out is page size over entry size, so entry size is the lever you control. A 4-byte INT gives roughly twice the children per page as a 16-byte binary UUID and about four times as many as a 36-character text UUID. The height rarely changes by more than one, but it also means 2 to 4 times more internal pages to cache, and every secondary index copies the primary key into each of its entries. Move the slider to see where a wide key tips an index into the next level. Text keys have another cost: InnoDB indexes can use at most 3,072 bytes of key in a dynamic row format table, and with utf8mb4 each character may need up to 4 bytes, so a VARCHAR(255) reserves up to 1,020 bytes in the worst case even if the average value is short. For long text where you only ever need a short prefix or an equality test, see the hash column pattern in B-tree vs hash. How random UUIDs also fragment the tree is in primary-key order.

Reference: the height vocabulary

Terms and what drives them What it means

Recap

Row size changes leaf pages, not the upper levels, so it hardly changes height. Upper levels are small and always cached. Real disk cost is the leaf (plus the table, for a secondary index). Wide or text keys shrink fan-out and are copied into every secondary index. Prefer compact keys, and count both trees for secondary lookups.

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.