Index-only scan (PostgreSQL)
A PostgreSQL index-only scan retrieves values from index entries and consults the heap when visibility cannot be established from the visibility map.
The index must support returning the needed values, and the query must be answerable from that index. A covering index can carry extra payload columns through INCLUDE, but that duplicates data and can increase index size. [1]
The plan name does not promise zero heap visits. For a candidate index tuple, a set all-visible map bit permits skipping the heap visibility check. A clear bit requires that check; returned values still come from the index. [1] [3]
In REL_16_15, Heap Fetches counts attempts to fetch a heap tuple for visibility, including attempts that find no visible tuple. It does not count unique pages or physical disk reads, and it is not a checksum-verification counter. [3]
A completed VACUUM does not promise a heap-free scan. In a controlled PostgreSQL 16.15 fixture, an old Repeatable Read snapshot and a Read Committed transaction with an assigned XID both prevented all-visible marking. The latter had null backend_xmin while idle. Releasing either holder alone left the fetch count unchanged until another VACUUM. These are fixture observations, not a timing benchmark. [6]
Relations
- related
- Visibility map (PostgreSQL), PostgreSQL TOAST, Detoasting, B-tree, B-link tree, Covering index, Secondary index, Query cardinality estimation, Hash index (PostgreSQL), Bitmap heap scan (PostgreSQL)
Citations
- PostgreSQL 16: Index-Only Scans and Covering Indexes
- PostgreSQL REL_16_15: IndexOnlyNext, visibility checks and heap-fetch instrumentation
- Hesela: PostgreSQL transaction horizons, three controlled 16.15 executions
Further reading
- PostgreSQL 16: Visibility Map
- PostgreSQL REL_16_15: ComputeXidHorizons, snapshot and assigned-XID cutoffs
- PostgreSQL REL_16_15: lazy_scan_prune, all-visible eligibility
Sources & caveats
- The counter interpretation is scoped to PostgreSQL REL_16_15. The linked Observatory demonstration uses synthetic clean rows, not injected corruption or a disk-I/O benchmark.