If the whole idea of the B+-tree structure, that the MySQL clustered index uses, is to be efficient in accessing disk data. Then it's logical to make index page size equal to the disk block size which is usually 512 bytes.

Then one physical disk lookup (required rotations and other movements) will provide us with one index page data. So why index page size is more like 16k instead? (As I understood, retrieving such a page requires reading of different disk blocks, not always sequential, and a lot of disk rotations).

What am I missing here?

  • Rotating hard drive throughput is ok for contiguous ("streaming") reads, terrible otherwise. Sure your file may not be all contiguous but under usual circumstances it will mostly be so.
    – Mat
    Nov 15 '21 at 18:24
  • For NTFS, the default cluster size is 4KB for disks up to 16TB, and ext2 and ext3 use cluster (block) sizes of 1 - 4KB. I'm not sure where you're getting that 512 bytes from. Nov 15 '21 at 18:29
  • Also, the chance that MySQL cluster blocks ever exactly match physical disk blocks is minimal, even when they are supposedly the same size.
    – KIKO Software
    Nov 15 '21 at 18:49
  • @BillKarwin more of a serverfault thing than dba, maybe?
    – ysth
    Nov 15 '21 at 19:25
  • I suspect very few databases where performance matters are not on SSDs now
    – ysth
    Nov 15 '21 at 19:26

InnoDB is full of compromises between speed and space.

InnoDB was designed before SSDs, so reading multiple adjacent disk sectors was a good idea, especially if you are likely to need more than just one piece of the 16KB block.

If you look at the disk usage for the entire database, you may find a "waste" of only a few percent when measuring space.

Also, today, most applications are small enough to fit entirely in RAM. So, the block size makes little difference. Actually, 16KB blocks is slightly faster on the initial load due to fewer I/Os, even for SSDs.

If you have a huge dataset and are I/O-bound you may get into performance difficulties if you mostly do random reads of one small row. Example: key-value dataset with UUIDs for ids. In this one use case, a smaller block size on SSDs might be noticeably faster.

Back to tradeoffs -- That UUID (etc) example is not very common.


InnoDB requires that at least two rows fit in a given page. This rule is bent a bit because the variable-length data types VARCHAR, VARBINARY, TEXT, and BLOB may overflow to additional pages. Both otherwise, a given row must fit within a little less than 8KB.

If the InnoDB page size were smaller than the current default of 16KB, the size limit of a row would be lower than it currently is. In fact, you can reconfigure InnoDB to use different page sizes, and this does change the maximum row size.

The default of 16KB is considered appropriate for most cases. It's true that there's a chance it does not align with the disk sector size exactly, but hopefully when performance is crucial your queries read from the buffer pool, not from disk.


retrieving such a page requires reading of different disk blocks, not always sequential, and a lot of disk rotations

That is incorrect. A page is the unit of database I/O; the DBMS will read and write at least one page at a time atomically, possibly more (i.e. multiple pages), especially when reading. This means a page is always contiguous on media (barring relocation at the physical drive level).

it's logical to make index page size equal to the disk block size which is usually 512 bytes

That is also somewhat incorrect. When choosing the page size one needs to find a sweet spot between the efficiency of large sequential I/O operations and wasted bandwidth when you only need a small portion of data from what you read. There is also another constraint: an index key cannot span pages, so your index page size (minus overhead) must be able to accommodate at least two key values; 512 byte pages won't be practical from that point of view.

Some DBMSes allow the DBA to choose different page sizes for different tables and indexes, thus enabling more precise tuning of I/O performance for particular scenarios.

See also this somewhat related Q&A -- it's not about MySQL but it shows some reasoning behind the page size choices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy