Tables, rows and keys
Almost every app that remembers something, from a bank to an airline booking system, relies on a database. The most common kind, the relational database, stores information in tables that resemble spreadsheets. Each row is one record, such as a customer, and each column holds one attribute, such as a name, phone number or date of birth. Every row has a unique identifier called a primary key, often a number. Tables link to each other through these keys: an orders table can store a customer number rather than repeating the customer’s details. Programs ask questions in a language called SQL, describing what they want, and the database decides how to fetch it efficiently.
The slow way: read everything
Data lives on disk or flash storage in fixed-size blocks called pages, often a few kilobytes each. Without any help, the only way to find a customer with a particular phone number is a full table scan: read every page and check every row. For a small table this is fine. For a table of a billion rows, spread across millions of pages, a scan can take minutes, and while it runs it competes with every other request for storage and memory. No app could make users wait that long for a balance check, so databases need a way to jump straight to the right place.
The index: a sorted shortcut
The answer is an index, which works like the alphabetical index at the back of a book. The database keeps a separate structure holding the values of one column, kept in sorted order, each paired with the location of its row. The most widely used design is the B-tree, invented in the early 1970s. Its top page divides the range of values into hundreds of slices, each pointing to a lower page that divides its slice again, and so on down to the bottom layer, which points to the actual rows. Because each page holds many entries, the tree stays shallow and wide, and only a few pages must be read to find any value.
Counting the steps
Imagine a national payments system with a billion account records. Simply halving the search each time, as you might with a sorted list, would take about 30 comparisons, since two multiplied by itself 30 times exceeds a billion. A B-tree does far better because each page can branch hundreds of ways. If each page points to about 500 others, three levels cover 125 million entries and four levels cover 62.5 billion. So any account can be reached by reading about four pages. The top levels are used so often that they usually sit in memory already, leaving perhaps one or two reads from storage, which is why a lookup can finish in a millisecond or less.
Indexes have a price
If indexes are so useful, why not index every column? Because each one is a separate copy of data that must be stored and kept up to date. Every time a row is added, changed or deleted, the database must also update every index on that table, so heavy indexing slows down writing. Indexes also take disk space and memory. Designers therefore index the columns that queries actually search or join on, such as account numbers, email addresses or dates. Databases include a component called the query planner, which estimates the cost of different approaches and decides whether to use an index or simply scan, depending on how much of the table a query needs.
From punched cards to the cloud
Early computer files were read in sequence, much like tape. In 1970 Edgar Codd, a researcher at IBM, proposed the relational model, separating how data is described from how it is physically stored. Commercial relational databases and the SQL language followed later that decade and still dominate. Since the 2000s, so-called NoSQL databases have stored data as documents, key-value pairs or graphs, often spread across many servers for enormous websites. Yet they rely on the same basic ideas: sorted structures, hashing and careful placement of data. Whether you check a balance, track a parcel or search an online shop, an index is quietly doing most of the work.
Sources & further reading
Figures are rounded and widely published; check the linked organisations for the latest editions. These organisations do not endorse this website.



