Repaso
EspaƱol
Databases & SQLIntermediateDB-01

What is the main cost of adding an index to a table?

Options

  1. Slower SELECT queries on the column that is indexed
  2. Extra storage and slower writes, since the index must be updated (Correct option)
  3. The table is locked permanently after the index is created
  4. Foreign keys are disabled on the table that is indexed

Answer

Extra storage and slower INSERT/UPDATE/DELETE because the index must be maintained

Why

An index is an extra sorted structure (usually a B-tree) that lets the database find rows quickly, like the index at the back of a book.

But every time you insert, update or delete a row, every index on that table must be updated too, and indexes take disk space.

So index the columns your important queries filter, join or sort on, not every column.

Remember

Indexes speed up reads and slow down writes.

Key terms

Practice this question in Repaso