Try
↑ ↓ move↵ openesc close
In this lesson · topic 1 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 1

Finding one row without reading them all

3 min read

Scan or look up

A table is stored in the order of its primary key. A query by that key walks a tree. A query by any other column has nothing to walk, so the engine reads every page and checks every row. In the lab a table of 5000 rows is 157measured pages, and a scan reads all of them.

A secondary index is another sorted tree. Its keys are the values of the column and its entries point back at the rows. Looking up a value now takes 4measured page reads in the lab, including the read of the row itself. The gap grows with the table. The scan grows in step with the row count. The index grows with its logarithm.

The second problem

Searching for a key in an LSM tree has a different version of this problem. A key may be in any of many files, and the engine does not know which. The same idea helps: keep a small summary so most files can be skipped. A Bloom filter is the summary that costs the least memory.

Predict first

A table has no index on the email column. A query asks for the row with one email address. How many rows does the engine look at?

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