Databasemaxxing: HOT or Not

on 2026-11-17

This writeup follows up on:

After delving into MVCC and the logical locks, we'll go a bit deeper into the page management side to wrap up.

Postgres uses a heap table storage structure. Tables are stored as a collection of fixed-size pages, with each page capable of holding multiple tuples (rows). This means that rows aren't necessarily stored on the same page. For example, searching for rows with IDs 1 and 2 could find both on page X, or find them on separate pages X and Y.

id '1' on page 1 slot 1 and id 2' on page 0 slot 2

id '1' on page 1 slot 1 and id 2' on page 0 slot 2

Postgres uses what's called a 'TID' (Tuple Identifier) and a 'CTID' (Current Tuple Id). TID is Postgres' physical tuple-location identifier, consisting of a page # and a slot #. CTID is the system column that exposes the TID of a specific tuple version in a table. If you followed the previous MVCC article, this is how transactions may see different versions of the same row due to multiple versions of a given row. The cool thing here is that this means indexes can avoid an extra logical lookup that another database may have to do.

Write Amplification

This is where the main concern of Postgres' tradeoff kicks in. Under MVCC, an update to a row will generate a new version of that row, so now we have row X with versions A and B. A table with indexes will need to account for the new CTID, introducing overhead with keeping an index synchronised.

Note: Indexes don't get modified in-place but store an additional entry referencing the new CTID.

Because Postgres has incredibly smart people behind it, an optimisation technique was created specifically for this: HOT (Heap Only Tuples).

Under HOT, indexes *may* avoid having to be synchronised under the following primary conditions:

  • The update doesn't modify any columns referenced by the table's indexes
  • The current page that the tuple lives on has enough space for its new version

So, what does that mean exactly? It means this:

If the new version can co-exist on the same page, indexes can continue referencing the original tuple, and Postgres can follow the HOT chain to locate the appropriate visible version.

Updates to non-indexed column generated HOTs with index still pointing to Page 0 Slot 1

Updates to non-indexed column generated HOTs with index still pointing to Page 0 Slot 1

You'll notice in the above that 't_ctid' for (0, 1) has the value (0, 2) (the next updated version) which also has (0, 3) to point to the next version. This is how the HOT chain forms when multiple versions of the same tuple exist on the same page. The index continues referencing the original tuple, and Postgres follows the HOT chain to locate the appropriate visible version.

Index scan -> locate original tuple -> follow HOT chain -> determine visible tuple

Index scan -> locate original tuple -> follow HOT chain -> determine visible tuple

With lots of updates, it's possible for intermediate versions of a tuple to be 'pruned' outside of VACUUM runs. During pruning, the original slot / line pointer can become a 'redirect' line pointer. Instead of pointing to the original tuple, it redirects to the oldest surviving tuple in the HOT chain.

Once the tuple has a non-HOT update performed, the index holds entries to the newest CTID and the old ones until it's been safely determined that clean up can be done once they're no longer needed.

Updating non-indexed column could've performed HOT but there was no space left on the page

Updating non-indexed column could've performed HOT but there was no space left on the page

This brings in the next point: how often will HOT occur? This is completely a 'it depends' situation that will be unique to you.

For example, some cases where HOT may not apply are:

  • If you have a table where the indexed columns are getting updated frequently over non-indexed columns
  • Postgres struggles to find space on the same page

Updating the indexed column requires updating the index -> can't perform HOT

Updating the indexed column requires updating the index -> can't perform HOT

Not enough space on page 0 for HOT

Not enough space on page 0 for HOT

You can see how HOT is performing as well via pg_stat_user_tables

Running lots of updates to increase HOT activity

Running lots of updates to increase HOT activity

The Fillfactor Theory

Would you believe it that the amazing people that work on Postgres also had another helpful optimisation for you? Fillfactor!

Fillfactor is a parameter on your tables to nudge Postgres "Hey try to leave x% space on pages that this table uses". For example, you want to have INSERTs up to 70% capacity and leave 30% for new tuple versions and other page activity. This is going to give updates a chance to have updated rows co-exist on the same page.

Modified table with a lower fillfactor, resulting in INSERTs being distributed across multiple pages rather than being packed onto the same page

Modified table with a lower fillfactor, resulting in INSERTs being distributed across multiple pages rather than being packed onto the same page

Note: Postgres can't do this for TOAST tables.