Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. A disk reads pages, not keys
  2. 2. Walking down, splitting up
  3. 3. Insert thousands of keys and count the pages
  4. 4. One small record, one whole page
  5. 5. The log lets the pages wait
  6. 6. How often to write the pages out
  7. 7. Pages, splits and the log

Topic 4

One small record, one whole page

4 min read

A page for a record

The disk wants a whole page. The application changed one record. So the engine writes a page of 4,096 bytesmeasured to save a record of 128 bytesmeasured. If every insert wrote its own page, the engine would write 32 timesmeasured more bytes than the application sent.

The lab shows it. With the log off, each insert must put its dirty pages on disk before it can finish, and the engine writes 1.09measured pages per insert. Write amplification is 35xmeasured.

Random keys spread the damage

Where the dirty pages are matters. With ascending keys, inserts keep landing on the same few leaves. Those pages change many times and are written once, and write amplification is only 2.4xmeasured. With random keys, the lab has to write 0.28measured pages per insert even with the log on, where ascending keys write 0.04measured.

Random keys also leave leaves only 70%measured full, against 100%measured for ascending keys. That means more pages for the same data and more to read.

Predict

A table gets random UUIDs as its primary key, and the table is much bigger than memory. What is the most likely effect on insert speed?

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