DEV Community

Muhammad Adil Shahid
Muhammad Adil Shahid

Posted on

1

A brief overview on Heap Only Tuple and Index Only Scans

Here we are going to discuss two features of postgresSQL that are very useful in enhancing its performance i.e.

  • Heap Only Tuple (HOT)

  • Index Only Scan

Heap Only Tuple

So basically in postgresSQL, when a row/tuple is updated, it is added as the new version. That tuple will have two versions the old one that is marked as deleted and the updated one that is marked as updated. But there is a problem in this case i.e. we have to manage two versions of a row.

To solve this problem, we use HOT. In Heap only tuple, we check the space on the page where old version tuple is located and if there is enough space, we create the updated version on the same page where old version is present.

Index Only Scan

In psotgresSQL, when a database query needs the index and data of column, we have to go to the table to get that column. This process involves a lot of disk I/O and eventually this thing results in very slow execution of query.

To solve this problem, here comes the index only scans. To reduce that I/O cost, index-only scans directly use the index key without accessing the corresponding table page when all entries of the SELECT statement are included in the index key. But there is certain criteria to use index-only scans:

  • The query must retrieve only those columns that are included in index.

  • Index type must support index-only scans such as b-tree index.

References

https://www.interdb.jp/pg/pgsql07.html
https://www.postgresql.org/docs/current/indexes-index-only-scans.html

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay