Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Databases
Databaseseasy

What does an index do and what is the main trade-off?

Tags
#index#performance#tradeoffs
Back to categoryPractice quiz

Answer

An index speeds up reads (filtering/sorting) by avoiding full table scans. The trade-off is slower writes (INSERT/UPDATE/DELETE) and extra storage because the index must be maintained.

Advanced answer

Deep dive

Indexes are additional data structures (often **B-trees**) that let the database find rows without scanning the whole table. They help with:

  • `WHERE` filters,
  • `JOIN` lookups,
  • `ORDER BY` / `GROUP BY` (sometimes),
  • uniqueness enforcement (unique indexes).

The main trade-off

Every write must update all relevant indexes, so:

  • writes get slower,
  • storage increases,
  • maintenance work grows (stats/vacuum/reindex depending on DB).

Practical tips

  • Prefer indexes on columns with good selectivity (many distinct values).
  • For composite indexes, column order matters (left-prefix rule): index on `(a, b)` helps queries filtering by `a` (and by `a` + `b`), but not just by `b`.
  • Avoid redundant indexes (they add write cost without benefit).

Common pitfalls

  • Indexing boolean/low-cardinality columns and expecting big wins.
  • Too many indexes on a hot write table.
  • Not verifying with `EXPLAIN` whether the planner actually uses the index.

Related questions

Databases
Denormalization: when might you do it and what’s the trade‑off?
#database#denormalization#performance
Databases
What is a covering index (index‑only scan) and why can it be faster?
#database#indexes#covering-index
Databases
Why can the optimizer choose a bad query plan and how do statistics help?
#optimizer
#statistics
#cardinality
Databases
Index selectivity: what is it and why does it matter?
#indexes#selectivity#performance
Databases
What is write amplification and why do many indexes make writes slower?
#performance#indexes#write-amplification
Databases
What is a materialized view and when would you use it?
#views#materialized-view#performance