The B-tree index size calculator gives the entries per page, the number of leaf pages, the height of the tree and the size of the index for a database table, from the row count, the key and pointer sizes, the page size and the fill factor.
How the calculation works
- Enter the number of rows, the key size and the pointer size.
- Pick the page size and enter the fill factor.
- The calculator gives the height, the entries per page, the leaf pages, the total pages, the index size, the inner pages size and the bytes per row.
Example
For 50,000,000 rows with an 8-byte key and an 8-byte pointer, a page of 8 KB filled to 70 % holds 358 entries. The index needs 139,665 leaf pages and 4 levels, in 140,056 pages, which is 1,094.2 MB, or 22.9 bytes per row. The inner pages total only 3.06 MB, so they stay in memory.
Why it matters
The calculator helps database administrators, developers and students to estimate the disk and memory footprint of an index, to see why lookups stay fast on huge tables and to compare key choices, such as a 4-byte integer or a 16-byte identifier.
Good to know
The model treats inner and leaf entries as the same size, which is close for fixed-size keys. Variable-length keys such as text reduce the fan-out, and long keys can make the tree one level higher. Real systems add page headers, row identifiers and sometimes compress the keys or trim common prefixes, so measured sizes differ by some percent. Wide keys are costly twice, since they also appear in every inner page. Compare the result with the size of the table to judge whether another index is worth its maintenance, because every index slows down inserts and updates. A hash index is smaller and faster for exact matches but cannot answer range queries.
Related tools
The hash collision calculator describes hash tables, the binary search calculator covers sorted arrays, the page table size calculator shows another multi-level tree and the hard drive access time calculator explains the cost of a disk read.