Intuition The ONE core idea
A table is just a big pile of rows on a disk , and finding one row by reading them all is painfully slow because disk reads are the bottleneck. An index is a second, cleverly-organized copy of one column that lets you jump to the row you want — the whole topic is about which organization (sorted tree, hash bucket, or word-list) makes which kind of jump fast.
Before you can read the parent note, you need to own every symbol and word it throws at you. This page builds each one from nothing, in the order they depend on each other. Nothing here is assumed — if the parent used it, we define it.
Definition Row, table, and the "heap"
A row is one record — think one line in a spreadsheet (one person: name, email, age). A table is the whole spreadsheet: many rows stacked. When rows are just dumped one after another with no ordering, that pile is called a heap .
Picture a shoebox stuffed with index cards, one card per person, in the order they walked in the door. That shoebox is the heap. There is no rule about where any card sits.
Look at the figure. To find the card for "email = zara@x.com " you have no shortcut — you pull card 1, check, pull card 2, check... until you hit it or run out. That "check every card" motion is the enemy this whole topic defeats.
N
N is just a name for the number of rows in the table . If the table has a billion rows, N = 1 , 000 , 000 , 000 . We use a letter instead of a number because the rules we discover must work for any table size.
Why we need it: every cost we talk about ("how much work?") is measured as a function of N . A shortcut that saves nothing when N is small but saves everything when N is huge is exactly what an index is — so we must be able to talk about N growing.
Definition Disk vs memory, page, and I/O
Memory (RAM) is the fast scratchpad the CPU works in; it is emptied when power goes off. Disk (a hard drive or SSD) is the slow-but-permanent storage where the table really lives. Data moves between them in fixed chunks called pages (commonly ~8 KB each). One trip to fetch a page from disk is one I/O ("Input/Output" operation).
Intuition WHY we count disk reads and ignore CPU
A modern CPU compares millions of values per millisecond — comparing is free . But a spinning disk does only ~100 random page-fetches per second; an SSD maybe ~10,000. So the only cost that matters is: how many pages did we have to drag off the disk? Every "cost" in this topic is a count of page reads, nothing else.
This is why the parent keeps saying "the bottleneck is not CPU, it is disk I/O." Hold onto this: fewer page reads = faster query , full stop. See Disk vs Memory I/O .
Definition Big-O notation,
O ( ⋅ )
O ( something ) is a shorthand for ==how the work grows as N grows==, ignoring constants and small stuff. Read O ( N ) as "grows in step with N " (double the rows → double the work). Read O ( 1 ) as "constant — same work no matter how big N is." Read O ( log N ) as "grows very slowly — the log of N ."
Intuition The picture of these three growth rates
Imagine three staircases as N climbs from 1 to a billion. O ( N ) is a steep ramp shooting to the ceiling. O ( log N ) barely rises — a gentle slope. O ( 1 ) is a flat floor. The whole game of indexing is turning the steep O ( N ) ramp into the gentle O ( log N ) slope or the flat O ( 1 ) floor.
See Big-O Notation for the full treatment. For this topic you only need the ordering: O ( 1 ) < O ( log N ) < O ( N ) , and to know that "full table scan" means O ( N ) = read every page.
The parent writes log m N and ⌈ log m N ⌉ . Let us earn every piece.
log b x — "the undo of raising to a power"
Raising to a power asks: "b multiplied by itself h times is what?" — that is b h . The logarithm asks the reverse question: "b multiplied by itself how many times gives x ?" We write that count as log b x . So log b x = h means exactly b h = x . They undo each other.
Intuition WHY a logarithm and not something else
A B-tree fans out: one node points to m nodes, each of those points to m more. After h levels you can reach m × m × ⋯ = m h leaves. To cover all N rows we need m h ≥ N . The question "how many levels h ?" is literally "how many times must I multiply m to reach N ?" — and that question's name is log m N . The log is not a random choice; it is the one tool that answers this exact question.
Worked example Feeling how slow the log grows
With branching m = 100 : log 100 100 = 1 , log 100 10 , 000 = 2 , log 100 1 , 000 , 000 = 3 . Each time we jump the row count by a factor of 100, the log goes up by just one . A billion rows (1 0 9 ) gives log 100 1 0 9 = 2 9 = 4.5 . That tiny number is why a B-tree reaches any row in a handful of page reads.
Definition The ceiling brackets
⌈ ⌉
⌈ x ⌉ means ==round x UP to the next whole number==. ⌈ 4.5 ⌉ = 5 . WHY here: you cannot have half a level in a tree — a partly-needed level is a whole extra level — so the height is ⌈ log m N ⌉ .
m (branching factor / fan-out)
m is how many children one tree node can point to . Because one node is packed into one disk page (~8 KB) and each key+pointer is small, m is often in the hundreds . Big m → the tree is wide and shallow → fewer levels → fewer disk reads. This is the single number that makes B-trees win.
You will meet m again inside B+ Tree Data Structure ; here just remember: large m shrinks the height , and height = number of disk reads.
Definition Key and row-pointer
A key is the value you search by — the email, the id, the age: whatever column the index is built on. A row-pointer is a tiny address saying "the full row lives over there on disk." An index entry is the pair (key → row-pointer) : sorted by key so you can find it, plus the address so you can fetch the real row.
Picture the book index at the back: the word is the key, the page number is the pointer. The index is small because it holds only these two things, not the whole rows.
Definition Sorted / ordered
Sorted means arranged smallest-to-largest (or A→Z). The value of sorting: once things are in order you can (a) find one by "smart guessing" (binary-search style) and (b) grab a range ("everything from 20 to 30") by starting at 20 and walking forward until you pass 30.
Keep this word close: a B-tree keeps keys sorted (so ranges and ORDER BY are cheap), while a hash deliberately throws order away (so it can't do ranges at all). Half the parent's comparison table is just this one distinction.
Definition Hash function and bucket
A hash function hash ( k ey ) is a machine that scrambles any key into a number. A bucket is one numbered slot in a big array. We pick the slot with
bucket = hash ( k ey ) mod B
where B = number of buckets and mod ("modulo") means the remainder after dividing , which wraps the scrambled number into the valid range 0 … B − 1 .
O ( 1 ) — and why it kills ranges
To find a key you don't search — you compute its bucket and jump straight there: constant work, O ( 1 ) , no matter how big N is. The catch: scrambling sends 99 and 100 to unrelated buckets, so "give me everything between 99 and 105" has nowhere to walk — the neighbours aren't neighbours anymore. That single trade-off is why hash is brilliant for = exact and useless for <, >, BETWEEN, ORDER BY.
See Hashing for collisions and bucket details.
These four terms power the full-text section.
Definition The full-text vocabulary
Tokenization = chop a sentence into individual words ("the cat sat" → the, cat, sat).
Stemming = cut words down to their root so variants match (running, ran → run).
Stop-word removal = throw away ultra-common filler (the, is, a) that helps no search.
Postings list = for one word, the sorted list of document IDs that contain it (e.g. sat → {D1, D2}).
Definition Inverted index
A normal index maps document → its words . An inverted index flips that to word → documents . WHY flip: your search gives you a word and asks for the documents — so you want the arrow pointing from word to documents. Answering cat AND dog then becomes intersecting two postings lists (set operations), which is fast because the lists are pre-sorted.
cost = count of disk reads
Big-O growth O(N) O(logN) O(1)
This map is the parent note's skeleton: the left column (rows, pages, cost) is why indexes exist; log m N and m build the B-tree ; the hash function builds the hash index ; the word-tools build the full-text index . Master this page and the parent reads like a story you already know. Related deeper notes: Clustered vs Non-clustered Index , Query Optimization .
Cover the right side and answer each before opening the parent.
What does N stand for in every cost formula? The number of rows in the table.
Why do we count disk page reads instead of CPU comparisons? Disk I/O is thousands of times slower than CPU; page reads are the real bottleneck.
Read out loud: O ( 1 ) , O ( log N ) , O ( N ) . Constant (flat), grows very slowly (gentle slope), grows in step with N (steep ramp).
What question does log m N answer? How many times must you multiply m by itself to reach N — i.e. how many tree levels.
Compute log 100 1 0 9 and explain the shortcut. 9/2 = 4.5 , using log 100 x = l o g 10 100 l o g 10 x = 2 9 .
What does ⌈ 4.5 ⌉ equal and why round up? 5 ; a partly-needed level is still a whole extra level.
What is m (branching factor) and why big is good? Children per node; large m makes the tree wide and shallow, so fewer disk reads.
What two things are in one index entry? A key (the searched value) and a row-pointer (address of the full row).
Why can a hash index do O ( 1 ) equality but no ranges? You compute the bucket directly (constant), but hashing scatters order so neighbouring values land far apart.
What does mod B do in hash ( k ey ) mod B ? Gives the remainder after dividing, wrapping the hash into a valid bucket number 0.. B − 1 .
Define an inverted index and why it's "inverted". Maps word → documents (flipping document → words), because a search gives a word and asks for documents.
Name the three text preprocessing steps. Tokenization, stemming, stop-word removal.