Toolvito

Works on this device

Index Size Calculator

Estimate how much space a B-tree index takes: rows × entry bytes ÷ fill factor, counted in whole pages with the levels of the tree. Choose an engine example or type your own figures. The result is an estimate, and the page says what it leaves out.

Enter your values

Rows × entry bytes ÷ fill factor, counted in whole pages, with the upper levels of the tree. Choose an engine example or type your own figures.

Your values

Rows that have an entry in the index. A partial index, or NULLs that an engine leaves out, give fewer.

The indexed columns added up: 4 for an int, 8 for a bigint or a timestamp, 16 for a UUID. Text: its mean bytes plus 1 or 2 for its length. In a MySQL secondary index add the primary key columns.

The header of an entry and the pointer to its row. Choose an engine example above, or type your own figure.

The pointer to the entry kept in the page (a line pointer or row offset). It is not rounded.

The key and the added bytes together are rounded up to this. PostgreSQL rounds to 8 bytes on 64-bit systems.

The page header and other fixed parts that hold no entries.

The share of each leaf page that is filled when the index is built. Pages that later split are about half to two thirds full.

More options

The share of each page above the leaves that is filled. These pages are a small part of the size.

Pages that every index has, such as the meta page of a PostgreSQL B-tree (1).

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Calculate.

How to use this calculator

  1. Choose Size of one B-tree index, or All the indexes of one table to add up several.
  2. Pick an engine example. It fills the added bytes, the page size and the fill factor. You can change every value.
  3. Type the rows and the key bytes of one entry. Add up the indexed columns with the table below.
  4. Choose Calculate. You get the size, the pages at each level and the working.

The formula

  • Entry = (key bytes + bytes added to each entry) rounded up to the alignment, + slot bytes.
  • Entries in a page = (page size − fixed bytes of the page) × fill factor ÷ entry bytes, rounded down.
  • Leaf pages = rows ÷ entries in a page, rounded up. Each upper level = pages below ÷ entries in an upper page, rounded up, until one root page.
  • Size = all pages × page size.

Engine examples

These presets are labelled examples of how each engine stores a B-tree entry. They fill the fields; check them against the documentation of your version.

Figures each engine example fills in
Example Added bytes Slot Rounded to Page Fixed bytes Fill factor
PostgreSQL 16 and 17 B-tree 8 (tuple header with row pointer) 4 (line pointer) 8 8,192 40 (24 header + 16 B-tree data) 90% leaves, 70% upper pages
SQL Server 2019 and 2022, index on a heap 9 (1 row header + 8 row ID) 2 (row offset) 1 8,192 96 (page header) 100% (fill factor 0)
SQL Server, index on a clustered table 1 (row header); add the clustered key to the key bytes 2 1 8,192 96 100%
MySQL 8.0 and 8.4 InnoDB secondary index 5 (compact record header); add the primary key to the key bytes 0 1 16,384 128 (headers, infimum, supremum, trailer) 93.75% (1/16 left free)

Bytes of common key columns

Stored bytes of one value
Column PostgreSQL MySQL InnoDB SQL Server
Small whole number smallint: 2 SMALLINT: 2 smallint: 2
Whole number integer: 4 INT: 4 int: 4
Big whole number bigint: 8 BIGINT: 8 bigint: 8
UUID uuid: 16 BINARY(16): 16 uniqueidentifier: 16
Date date: 4 DATE: 3 date: 3
Date and time timestamp: 8 DATETIME: 5 (+ up to 3 for fractions) datetime2(7): 8; datetime: 8
Short text bytes + 1 (up to 126 bytes) bytes + 1 or 2 bytes + 2, plus 2 for the row

Worked examples

PostgreSQL: a bigint key (8 bytes) on 10,000,000 rows. Entry = (8 + 8) rounded to 8 = 16, + 4 = 20 bytes. A leaf page holds (8,192 − 40) × 90% ÷ 20 = 366.84, so 366 entries. That is 27,323 leaf pages. Upper pages hold (8,152 × 70%) ÷ 20 = 285 entries, so the levels above have 96 pages and 1 root page. With the meta page: 27,421 pages × 8,192 bytes = 224,632,832 bytes, about 214.2 MiB.

SQL Server on a heap: an int key (4 bytes). Entry = 4 + 9 + 2 = 15 bytes, 8,096 ÷ 15 = 539 entries in a page at fill factor 100.

What the estimate leaves out

  • Bloat: an index that grows by random inserts has pages about half to two thirds full, and deleted rows leave space until it is reused. A real index can be up to twice this estimate.
  • Compression, deduplication of equal keys (PostgreSQL 13 and later) and prefix compression make an index smaller.
  • Text keys of different lengths: the estimate uses one mean entry size. Long values that an engine stores outside the page are not covered.
  • NULLs that an engine leaves out of an index, partial and filtered indexes: type the rows that really have an entry.
  • Upper pages are worked out with the same entry size as the leaves; in a real tree they hold only keys and child pointers.
  • The tool measures nothing. To see a real size, ask your database (for example pg_relation_size in PostgreSQL).

Related tools