Gnoseed
Databases · Flashcard

Why does SELECT count(*) on a big PostgreSQL table take so long?

Why this is the answer

Row visibility depends on each transaction's snapshot, so an exact count must scan (index-only at best) — estimates live in pg_class.reltuples. count(*) vs count(1) is a myth (identical performance), no VACUUM is triggered, and counting takes no exclusive lock.

Read more in the docs
Study in Gnoseed →