Database indexes speed up searches. What is their cost?
Extra work on writes, because every index must stay synchronized.
- They make all queries slower
- They add overhead to data changes ✔
- They delete old rows
Why: An index works like the index at the back of a book, letting the database jump to matching rows. But every insert, update and delete must also update each index, so adding indexes everywhere backfires.
Huh, didn't know that: PostgreSQL automatically creates a unique B-tree index for a declared primary key.
I added an index to my diary. Now I can find my bad decisions in O(log n).
References
Answer: They add overhead to data changes. An index works like the index at the back of a book, letting the database jump to matching rows. But every insert, update and delete must also update each index, so adding indexes everywhere backfires.
- PostgreSQL Documentation: Indexes www.postgresql.org/docs/current/indexes.html
But indexes also add overhead to the database system as a whole, so they should be used sensibly.
Checked 2026-10-10.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.