Skip to content
Databases

Indexes: a shortcut with a maintenance cost

Why a lookup gets faster, why writes get a little slower, and how to read the trade-off.

Community contributor10 min readQuick checkSources

A database index is an additional structure that helps the engine find rows without scanning every row in a table. Like the index at the back of a textbook, it maps a value to where the useful material lives.

Faster reads are not free

The database must update each relevant index when rows change. Indexes also use storage and can change which query plan the engine chooses. The right index follows a real query pattern; adding one to every column usually adds cost without a matching benefit.

Quick check

Why can adding many indexes slow down writes?

Show answer

Each insert, update, or delete may need to maintain several index structures as well as the table row.

Sources

  1. 1.PostgreSQL indexes · PostgreSQL · docs (opens in a new tab)
  2. 2.Use The Index, Luke · book · guide (opens in a new tab)

Was this chapter useful?

Editors read every answer.

Star this chapter

Each star goes once to every reader who improved this chapter.

Finished reading?

Mark it to keep your place in the course.