Skip to content
Omnikalc

B-tree index size calculator

Enter the number of rows, the key and pointer sizes, the page size and the fill factor to get the entries per page, the leaf pages, the height of the tree and the size of the index.

Updated on
Your inputs

Value out of range

bytes

Value out of range

bytes

Value out of range

%

Value out of range

Results

Height of the tree (levels)

4

Entries per page
358
Leaf pages
139,665
Total pages (approximately)
140,056
Index size
1,094.2 MB
Inner pages only
3.06 MB
Index bytes per row
22.9 bytes

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.

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.

Frequently asked questions

How is the height of a B-tree computed?

Each page holds a few hundred entries, so each level multiplies the number of reachable rows by that fan-out. The leaf level needs rows / entries pages, and the number of levels above is the logarithm of the leaf count in base fan-out, rounded up. With 358 entries per page, 50 million rows need just 4 levels.

Why is the fill factor below 100 %?

Pages are split when they overflow, and each half starts about half full. Random insertions leave pages around 68 to 70 % full on average, while a bulk load of sorted data can fill them to 90 or 100 %. A lower fill factor makes the index bigger but leaves room for later inserts without splits.

How many disk reads does a lookup need?

At most one per level, which is the height. The root and the inner pages are small, a few megabytes here, and normally stay in memory, so a lookup often costs a single disk read for the leaf page, plus one for the table row if the index is not covering.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.