The Real Cost of Indexes
Indexing isn't free. Let's look at what we actually pay for faster reads.

The Real Cost of Indexes
We all hear:
"Oh, the query is slow? Just index it."
So we start thinking:
"If a query is slow, an index will make it faster."
But does it always?
And more importantly, at what cost?
What do we buy from indexing?
- Faster lookups
- Ordered range scans
- Fast sorting on indexed columns
And what do we pay for it?
1. Storage
If I don't have indexing, I have to scan through millions of rows.
An index is simply another data structure storing information about your table.
So when we create an index, we're storing additional data alongside the actual table.
This means more storage and more data to maintain.
The size of an index isn't a fixed percentage of the table. It depends on things like the size of the indexed values, number of rows, and the structure of the index.
An index on a small table might barely matter.
An index on a table containing billions of rows is a completely different story.
2. Slower writes
How does indexing affect writes?
First, you must know that indexing is used when we need faster retrieval, so it is great for read-heavy tasks.
And how is it making the read faster?
Imagine a table:
id name age
1 Ram 21
2 Arun 25
3 John 21
4 Priya 25And we index the age column.
If the DB uses a B+ tree for indexing, conceptually, the index looks something like:
age index
/ \
21 25
/ \ / \
row 1 row 3 row 2 row 4Or, if we simplify it into a table:
age β row reference
---------------------------
21 β row 1
21 β row 3
25 β row 2
25 β row 4So if the query is "bring me a particular name of age 21", we traverse through the tree, almost cutting the nodes needed to look up by half, and reach the correct node and find the data.
Now the next jump will be directly to the row containing the data we need on disk.
So from sequential scanning β O(n) β to potentially O(log n).
With a B+ tree index, the lookup is O(log n) for finding the relevant index entry, but getting the actual row is an additional cost.
Also, with duplicate values like age = 21, you may need to traverse multiple matching entries. It is still efficient in this case compared with going through all rows.
The index stores the indexed value + something that tells the database where the actual row is.
So what happens when we write something?
Imagine you add a row:
INSERT INTO users VALUES (5, 'Kiran', 21);The table becomes:
id name age
1 Ram 21
2 Arun 25
3 John 21
4 Priya 25
5 Kiran 21 β newAnd now the index must be updated too:
age β row
21 β 1
21 β 3
21 β 5 β new
25 β 2
25 β 4This is just a simplified representation.
If the indexing was implemented using a B+ tree, then it has to navigate through the tree, find where to store the new entry, and store it.
If the node has no room for the new entry, or has reached its maximum capacity, the node may need to be split. The parent must then be updated, which can increase the amount of work and, in some cases, the number of I/O operations.
Note: Not every write causes an extra split or extra I/O.
The same goes for updating and deleting:
INSERT β add entry to the index
UPDATE β potentially modify the index entry
DELETE β remove the index entryHow does the database traverse a B+ tree?
Let's look at this example, with the actual table on the left and the B+ tree indexed on email on the right.
Now I must search for john@gmail.com.
First, I come to the root node, and I make a lexicographical comparison between john@gmail.com and kiran@gmail.com.
Since john@gmail.com comes before kiran@gmail.com, we go left.
Now we are in the leaf node. We find the email, and now we know which row this data is in.
So why does it become a problem when inserting, deleting, or updating?
When we insert a new row, the database must also insert the corresponding entry into the index.
When we delete a row, its entry must be removed.
When we update an indexed value, the index must be updated as well.
And while modifying the tree, a node can overflow or underflow, which may require splitting, merging, or redistributing nodes.
So every index we add means additional work during writes.
Over-indexing is an issue too
Suppose you create separate indexes on five columns, and you write something.
The database doesn't just update the table. It potentially has to update the five index structures too, making the write more expensive and also leading to more storage usage.
few indexes β less maintenance per write
many indexes β more maintenance per writeAn index that is heavily used is valuable to keep cached.
But when we over-index, some index pages may not be very useful to cache, yet they can still occupy limited RAM, making useful pages compete for cache space.
The Conclusion
Indexing isn't automatically good.
We are basically trading something for faster reads.
We use more storage, and every insert, update, or delete may also have to update the index.
So the real question is whether those faster reads are worth the extra cost.
You don't get faster reads for free. You pay for them elsewhere.