Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. Finding one row without reading them all
  2. 2. Secondary indexes and Bloom filters
  3. 3. Tune a filter and add indexes
  4. 4. Each index is a tax on every write
  5. 5. Bits per key against false positives
  6. 6. Where filters help and where they do not
  7. 7. False positives, hashes and index cost

Topic 4

Each index is a tax on every write

4 min read

The write bill

A table with no secondary index appends a new row to its last page. The lab counts 0.03measured page writes per insert, because a page holds many rows and is written once when full.

An insert into a table with indexes must also place an entry in every index. The entries land in random leaf pages, since the indexed values are not in arrival order. With 2 indexes the lab writes 0.36measured pages per insert. With 5 it writes 0.86measured. That is 26 timesmeasured the cost of no indexes.

The same happens in the log, because each index change is a log record, and in the cache, because the index pages compete with table pages for memory.

When an index hurts

An index pays off when queries use it often enough to cover the writes it slows. It hurts when:

  • the table takes many writes and few reads by that column,
  • the column is updated often, so each update moves an entry,
  • the column has few distinct values, so the index narrows nothing,
  • another index already serves the query.

Dropping an unused index is a free speed-up for every write. Finding which are unused is the hard part, and databases keep counters for that.

Predict

A table takes constant inserts and a handful of reads a day. It has six secondary indexes. What is the best first step?

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms