{"schema": "pgtrue.report/1", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d", "published": "2026-10-21T05:00:45Z", "publisher": "PostgresAI", "article": {"title": "PostgreSQL Index-Only Scans: Why Your Covering Indexes May Be Lying to You", "url": "https://mvpfactory.io/blog/postgresql-index-only-scans-and-visibility-maps-the-query-optimization-that", "date_published": "2026-08-18T00:00:00Z", "author": "Krystian Wiewi\u00f3r", "publisher": "mvpfactory.io"}, "grade": "B+", "axes": [{"axis": "Factual", "summary": "B+ \u00b7 1 wrong of 15 checked \u00b7 0 caveats"}, {"axis": "Applicable", "summary": "B \u00b7 3 wrong of 6 checked \u00b7 0 caveats"}, {"axis": "Consistent", "summary": "B+ \u00b7 1 wrong of 15 checked \u00b7 0 caveats"}, {"axis": "Transparent", "summary": "0 wrong \u00b7 1 caveat \u00b7 1 checked"}, {"axis": "Safe", "summary": "A \u00b7 0 wrong of 5 checked \u00b7 0 caveats"}], "findings": [{"anchor": "F1", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F1", "claim": "\u2026pg_relation_size( oid )\u2026", "title": "The VM monitoring query references a nonexistent column", "explanation": "The VM query fails because pg_stat_user_tables exposes relid, not oid. src/backend/catalog/system_views.sql:681 defines that alias. Lines 749-752 define the user-table view. Replace both oid references with relid.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L679-L701", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:679-701"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L749-L752", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:749-752"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_functions.sql#L285-L289", "label": "REL_18_6 \u00b7 src/backend/catalog/system_functions.sql:285-289"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/func.sgml#L30159-L30162", "label": "REL_18_6 \u00b7 doc/src/sgml/func.sgml:30159-30162"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L679-L716", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:679-716"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L749-L752", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:749-752"}]}, {"anchor": "F2", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F2", "claim": "High-write tables need aggressive autovacuum_vacuum_scale_factor (1-2%)\u2026", "title": "The tuning recommendation misses the insert-trigger parameters", "explanation": "Lowering autovacuum_vacuum_scale_factor does not advance insert-triggered vacuums. src/backend/postmaster/autovacuum.c:3122-3127 calculates separate dead-tuple and insert thresholds. Insert-heavy event tables require checking the insert-trigger parameters.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L3122-L3127", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:3122-3127"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L3145-L3146", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:3145-3146"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L9131-L9134", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:9131-9134"}]}, {"anchor": "F3", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F3", "claim": "\u2026if query latency drops significantly after a manual VACUUM, you\u2019ve just confirmed the real bottleneck\u2026", "title": "Faster execution after VACUUM ANALYZE does not isolate VM coverage", "explanation": "Faster execution after VACUUM ANALYZE does not identify VM coverage as the cause. src/backend/commands/vacuum.c:666 also runs ANALYZE. That updates planner statistics. Compare plans and heap-fetch counts before changing autovacuum.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/vacuum.sgml#L142-L143", "label": "REL_18_6 \u00b7 doc/src/sgml/ref/vacuum.sgml:142-143"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/vacuum.c#L666-L667", "label": "REL_18_6 \u00b7 src/backend/commands/vacuum.c:666-667"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/vacuum.sgml#L519-L519", "label": "REL_18_6 \u00b7 doc/src/sgml/ref/vacuum.sgml:519-519"}]}, {"anchor": "F4", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F4", "claim": "\u2026If vm_visible_pages is significantly less than heap_pages , your index-only scans are paying for heap fetches\u2026", "title": "Table-wide VM coverage does not determine a query\u2019s heap fetches", "explanation": "A table-wide VM ratio does not determine heap fetches for a particular query. src/backend/executor/nodeIndexonlyscan.c:162-170 tests each candidate\u2019s heap page. A query restricted to all-visible pages can fetch zero heap tuples despite low table coverage.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}]}, {"anchor": "F5", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F5", "claim": "\u2026SELECT count ( * ) FROM pg_visibility( oid ) WHERE all_visible\u2026", "explanation": "After replacing oid with relid, the monitoring query reads every heap block. contrib/pg_visibility/pg_visibility.c:238 requests page-header data. Lines 559-577 read those blocks. Use pg_visibility_map_summary(relid) for routine coverage polling. The printed query itself fails before these reads.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L679-L701", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:679-701"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/system_views.sql#L749-L752", "label": "REL_18_6 \u00b7 src/backend/catalog/system_views.sql:749-752"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/contrib/pg_visibility/pg_visibility.c#L238-L238", "label": "REL_18_6 \u00b7 contrib/pg_visibility/pg_visibility.c:238-238"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/contrib/pg_visibility/pg_visibility.c#L559-L577", "label": "REL_18_6 \u00b7 contrib/pg_visibility/pg_visibility.c:559-577"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/pgvisibility.sgml#L96-L98", "label": "REL_18_6 \u00b7 doc/src/sgml/pgvisibility.sgml:96-98"}]}, {"anchor": "F16", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F16", "claim": "\u2026100\u2013500 rows/sec Marginally 10\u201340% > 500 rows/sec No 60\u2013100% Bulk ingest (ETL) No 100%\u2026", "title": "Write throughput alone does not establish the table's heap-fetch percentages", "explanation": "Rows/sec alone does not determine heap-fetch percentages. autovacuum.c:3122 computes thresholds from table size and tuple counts. nodeIndexonlyscan.c:162 checks each referenced page. The article supplies no workload or measurement basis for its 100/500 rows/sec bands. Those bands cannot establish another table's expected heap-fetch rate.", "verdict": "Mostly accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L3122-L3127", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:3122-3127"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}]}, {"anchor": "F8", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F8", "claim": "Only when the VM bit is set can an index-only scan skip the heap fetch entirely.", "title": "Index-only scans use each candidate page\u2019s all-visible bit", "explanation": "Index-only scans test each candidate page\u2019s all-visible bit before fetching the heap. src/backend/executor/nodeIndexonlyscan.c:162-171 implements that test. Heap headers store transaction IDs. Index entries reference heap tuples. VACUUM sets eligible VM bits. A covering index includes the query\u2019s required columns.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/vacuumlazy.c#L2924-L2939", "label": "REL_18_6 \u00b7 src/backend/access/heap/vacuumlazy.c:2924-2939"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/storage.sgml#L669-L672", "label": "REL_18_6 \u00b7 doc/src/sgml/storage.sgml:669-672"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/indices.sgml#L1213-L1215", "label": "REL_18_6 \u00b7 doc/src/sgml/indices.sgml:1213-1215"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/indices.sgml#L1241-L1244", "label": "REL_18_6 \u00b7 doc/src/sgml/indices.sgml:1241-1244"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L3196-L3196", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:3196-3196"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/include/access/htup_details.h#L122-L125", "label": "REL_18_6 \u00b7 src/include/access/htup_details.h:122-125"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/include/access/itup.h#L35-L37", "label": "REL_18_6 \u00b7 src/include/access/itup.h:35-37"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/vacuum.sgml#L519-L519", "label": "REL_18_6 \u00b7 doc/src/sgml/ref/vacuum.sgml:519-519"}]}, {"anchor": "F9", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F9", "claim": "\u2026autovacuum_vacuum_cost_delay = 2\u2026", "title": "The cost-delay setting uses milliseconds and defaults to 2", "explanation": "The base cost-delay setting defaults to 2 milliseconds. doc/src/sgml/config.sgml:9275-9279 defines its units. src/backend/postmaster/autovacuum.c:1658-1664 gives table settings precedence over global settings.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L9275-L9279", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:9275-9279"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L1658-L1664", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:1658-1664"}]}, {"anchor": "F10", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F10", "claim": "\u2026autovacuum_vacuum_cost_limit = 800\u2026", "explanation": "A table cost limit of 800 overrides the inherited worker limit. src/backend/postmaster/autovacuum.c:1733-1734 assigns it directly. The global parameter defaults to -1 and inherits vacuum_cost_limit. That parameter defaults to 200 cost units.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/postmaster/autovacuum.c#L1733-L1734", "label": "REL_18_6 \u00b7 src/backend/postmaster/autovacuum.c:1733-1734"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L9297-L9300", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:9297-9300"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/misc/guc_tables.c#L2678-L2679", "label": "REL_18_6 \u00b7 src/backend/utils/misc/guc_tables.c:2678-2679"}]}, {"anchor": "F12", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F12", "claim": "EXPLAIN (ANALYZE, BUFFERS)\u2026", "title": "EXPLAIN ANALYZE exposes index-only heap-fetch attempts", "explanation": "EXPLAIN ANALYZE reports heap-fetch attempts for index-only scans. src/backend/commands/explain.c:1982-1984 prints the counter incremented by src/backend/executor/nodeIndexonlyscan.c:169. The node label alone does not establish heap avoidance.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/explain.c#L1982-L1984", "label": "REL_18_6 \u00b7 src/backend/commands/explain.c:1982-1984"}]}, {"anchor": "F13", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F13", "claim": "\u2026diagnose heap fetch fallbacks with EXPLAIN ANALYZE\u2026", "title": "EXPLAIN ANALYZE exposes index-only scan heap fallbacks", "explanation": "EXPLAIN ANALYZE reports Heap Fetches for an Index Only Scan. src/backend/commands/explain.c:1982 prints ntuples2. src/backend/executor/nodeIndexonlyscan.c:169 increments that counter when the executor must check heap visibility.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/explain.c#L1975-L1988", "label": "REL_18_6 \u00b7 src/backend/commands/explain.c:1975-1988"}]}, {"anchor": "F14", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F14", "claim": "\u2026conditional nature of that promise\u2026", "title": "Covering an index does not guarantee heap avoidance", "explanation": "Index coverage does not establish tuple visibility. doc/src/sgml/indices.sgml:1205 describes the MVCC requirement. src/backend/executor/nodeIndexonlyscan.c:162 checks the candidate page's all-visible status. The executor fetches the heap when that check fails.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/indices.sgml#L1202-L1223", "label": "REL_18_6 \u00b7 doc/src/sgml/indices.sgml:1202-1223"}]}, {"anchor": "F15", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F15", "claim": "\u2026This isn\u2019t a permanent fix.", "title": "Manual VACUUM does not preserve visibility coverage through later writes", "explanation": "VACUUM can restore all-visible status, but later writes can clear it. src/backend/access/heap/vacuumlazy.c:99 describes setting visibility bits. src/backend/access/heap/heapam.c:2146 clears visibility state during insertion. Manual VACUUM provides no permanent guarantee for a changing table.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/heapam.c#L2138-L2157", "label": "REL_18_6 \u00b7 src/backend/access/heap/heapam.c:2138-2157"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/vacuumlazy.c#L95-L103", "label": "REL_18_6 \u00b7 src/backend/access/heap/vacuumlazy.c:95-103"}]}, {"anchor": "F18", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F18", "claim": "\u2026Heap Fetches: 0\u2026", "title": "Zero Heap Fetches means no heap visibility fetches", "explanation": "Heap Fetches: 0 means this index-only scan made no heap visibility fetches. explain.c:1983 prints the ntuples2 counter. nodeIndexonlyscan.c:169 increments that counter before each heap visibility fetch.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/explain.c#L1977-L1987", "label": "REL_18_6 \u00b7 src/backend/commands/explain.c:1977-1987"}]}, {"anchor": "F20", "url": "https://pgtrue.postgres.ai/shared/brief/5a8f2450-18a1-48f7-b638-399ce6bb682d#F20", "claim": "\u2026(actual time=0.341..1.204 rows=50) Heap Fetches: 2847\u2026", "title": "The heap-fetch and returned-row counts can coexist", "explanation": "The 2,847 heap-fetch attempts can produce 50 visible rows. nodeIndexonlyscan.c:169 counts attempts before visibility succeeds. Repeated attempts can reuse a pinned heap buffer. bufmgr.c:3055 returns that buffer without ReadBuffer. The 510 buffer accesses do not contradict 2,847 attempts.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeIndexonlyscan.c#L162-L171", "label": "REL_18_6 \u00b7 src/backend/executor/nodeIndexonlyscan.c:162-171"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/heapam_handler.c#L100-L160", "label": "REL_18_6 \u00b7 src/backend/access/heap/heapam_handler.c:100-160"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/storage/buffer/bufmgr.c#L3032-L3065", "label": "REL_18_6 \u00b7 src/backend/storage/buffer/bufmgr.c:3032-3065"}]}]}