{"Entry":{"collection":"plan","key":"index-only-scan","name":"Index Only Scan","aliases":["Index Only Scan","IndexOnlyScan","T_IndexOnlyScan"],"metadata":{"aliases":["Index Only Scan","IndexOnlyScan","T_IndexOnlyScan"],"category":"Scan","content_hash":"788b6c7dbf8a0476e6e73fe8a750a4dccf52593f2222ae4a01b19bf08c7385d4","imported_at":"2026-09-30T00:40:44.222116+08:00","name":"Index Only Scan","name_zh":"IndexOnlyScan","slug":"index-only-scan","summary":"Uses index values for the result and checks tuple visibility, visiting the heap when the visibility map does not suffice."}},"Definition":{"Collection":"plan","Key":"index-only-scan","SourceDatabase":"center","Version":"18","SourceTable":"plan_node","SourceKey":"index-only-scan","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"comparison_data":{"initializer":"ExecInitIndexOnlyScan","memory_mechanism":"unclassified","node_tag":"T_IndexOnlyScan","parallel_callbacks":["ExecIndexOnlyScanEstimate","ExecIndexOnlyScanInitializeDSM","ExecIndexOnlyScanInitializeWorker","ExecIndexOnlyScanReInitializeDSM","ExecIndexOnlyScanRetrieveInstrumentation"],"partial_modes":[],"strategies":[],"text_names":["Index Only Scan"]},"comparison_hash":"149a13d2842f396b0e35eb23a93337d9e8c708fbcf6665eec0ab0ebbd5320b9b","description":["Uses index values for the result and checks tuple visibility, visiting the heap when the visibility map does not suffice."],"evidence_kind":"source and documentation","explain_names":["Index Only Scan"],"explain_prefixes":["Parallel","Async"],"facts":[{"label":"Core node tag","value":"T_IndexOnlyScan"},{"label":"Structured EXPLAIN Node Type","value":"Index Only Scan"},{"label":"Inputs","value":"An index, relation and visibility information"},{"label":"Output","value":"Qualified tuples from index values"},{"label":"Executor initializer","value":"ExecInitIndexOnlyScan"},{"label":"Memory mechanism","value":"unclassified"}],"memory":{"description":"This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeIndexonlyscan.c","path":"src/backend/executor/nodeIndexonlyscan.c","sha256":"357d4ddbd6ba5d9b02f04185e579e2f2dc889d0d94875580770c8649cc427e6d","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"unclassified","source_notes":[]},"node_tag":"T_IndexOnlyScan","parallel_callbacks":["ExecIndexOnlyScanEstimate","ExecIndexOnlyScanInitializeDSM","ExecIndexOnlyScanInitializeWorker","ExecIndexOnlyScanReInitializeDSM","ExecIndexOnlyScanRetrieveInstrumentation"],"partial_modes":[],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"enable_indexonlyscan","url":"/wiki/guc/enable_indexonlyscan/?v=18"},{"label":"random_page_cost","url":"/wiki/guc/random_page_cost/?v=18"},{"label":"Index AM","url":"/wiki/indexam/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: Index Only Scan.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: ExecIndexOnlyScanEstimate, ExecIndexOnlyScanInitializeDSM, ExecIndexOnlyScanInitializeWorker, ExecIndexOnlyScanReInitializeDSM, ExecIndexOnlyScanRetrieveInstrumentation."],"title":"Parallel execution and instrumentation"},{"blocks":[{"code":"EXPLAIN SELECT *\nFROM tenk1 t\nWHERE t.unique1 NOT IN (SELECT o.unique1 FROM onek o);\n\n                                         QUERY PLAN\n--------------------------------------------------------------------------------------------\n Seq Scan on tenk1 t  (cost=61.77..531.77 rows=5000 width=244)\n   Filter: (NOT (ANY (unique1 = (hashed SubPlan 1).col1)))\n   SubPlan 1\n     -\u003e  Index Only Scan using onek_unique1 on onek o  (cost=0.28..59.27 rows=1000 width=4)\n(4 rows)","paragraphs":["Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.","In the example above, the ALL operator runs the subplan again for each row of the outer query (which accounts for the high estimated cost). Some queries can use a hashed subplan to avoid that:"],"source":{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-BASICS"}},{"code":"EXPLAIN ANALYZE SELECT four, unique1 FROM tenk1 WHERE four BETWEEN 1 AND 3 AND unique1 = 42;\n                                                              QUERY PLAN\n----------------------------------------------------------------------------------------------------------------------------------\n Index Only Scan using tenk1_four_unique1_idx on tenk1  (cost=0.29..6.90 rows=1 width=8) (actual time=0.006..0.007 rows=1.00 loops=1)\n   Index Cond: ((four \u003e= 1) AND (four \u003c= 3) AND (unique1 = 42))\n   Heap Fetches: 0\n   Index Searches: 3\n   Buffers: shared hit=7\n Planning Time: 0.029 ms\n Execution Time: 0.012 ms","paragraphs":["Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.","The “ Index Searches ” line is also useful with B-tree index scans that apply the skip scan optimization to more efficiently traverse through an index:"],"source":{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-ANALYZE"}}],"title":"Examples from this manual build"},{"paragraphs":["Determine which direction to scan the index in based on the plan's scan direction and the current direction of execution.","We reach here if the index only scan is not parallel, or if we're serially executing an index only scan that was planned to be parallel.","If no run-time keys to calculate or they are ready, go ahead and pass the scankeys to the index AM.","We can skip the heap fetch if the TID references a heap page on which all tuples are known visible to everybody. In any case, we'll use the index tuple not the heap tuple as the data source.","Note on Memory Ordering Effects: visibilitymap_get_status does not lock the visibility map buffer, and therefore the result we read here could be slightly stale. However, it can't be stale enough to matter."],"title":"Executor implementation notes"},{"code":"case T_IndexOnlyScan:\n\t\t\tpname = sname = \"Index Only Scan\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"source_inventory":{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeIndexonlyscan.c"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1447","line":1447,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:224","line":224,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeIndexonlyscan.c","path":"src/backend/executor/nodeIndexonlyscan.c","sha256":"357d4ddbd6ba5d9b02f04185e579e2f2dc889d0d94875580770c8649cc427e6d","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-BASICS"},{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-ANALYZE"}],"strategies":[],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"Index Only Scan","label":"Index Only Scan"}],"title":"EXPLAIN labels in this source build"}]},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1447","line":1447,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:224","line":224,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeIndexonlyscan.c","path":"src/backend/executor/nodeIndexonlyscan.c","sha256":"357d4ddbd6ba5d9b02f04185e579e2f2dc889d0d94875580770c8649cc427e6d","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-BASICS"},{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-ANALYZE"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"plan","Key":"index-only-scan","SourceDatabase":"center","Version":"18","Locale":"en","Title":"Index Only Scan","Summary":"Uses index values for the result and checks tuple visibility, visiting the heap when the visibility map does not suffice.","BodyHTML":"\u003cp\u003eUses index values for the result and checks tuple visibility, visiting the heap when the visibility map does not suffice.\u003c/p\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"213c9bc35ee0182fc346fcecc61380d394e6091b775a06f3897321932a2f20c9","Payload":{"description":["Uses index values for the result and checks tuple visibility, visiting the heap when the visibility map does not suffice."],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"enable_indexonlyscan","url":"/wiki/guc/enable_indexonlyscan/?v=18"},{"label":"random_page_cost","url":"/wiki/guc/random_page_cost/?v=18"},{"label":"Index AM","url":"/wiki/indexam/?v=18"}],"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: Index Only Scan.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: ExecIndexOnlyScanEstimate, ExecIndexOnlyScanInitializeDSM, ExecIndexOnlyScanInitializeWorker, ExecIndexOnlyScanReInitializeDSM, ExecIndexOnlyScanRetrieveInstrumentation."],"title":"Parallel execution and instrumentation"},{"blocks":[{"code":"EXPLAIN SELECT *\nFROM tenk1 t\nWHERE t.unique1 NOT IN (SELECT o.unique1 FROM onek o);\n\n                                         QUERY PLAN\n--------------------------------------------------------------------------------------------\n Seq Scan on tenk1 t  (cost=61.77..531.77 rows=5000 width=244)\n   Filter: (NOT (ANY (unique1 = (hashed SubPlan 1).col1)))\n   SubPlan 1\n     -\u003e  Index Only Scan using onek_unique1 on onek o  (cost=0.28..59.27 rows=1000 width=4)\n(4 rows)","paragraphs":["Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.","In the example above, the ALL operator runs the subplan again for each row of the outer query (which accounts for the high estimated cost). Some queries can use a hashed subplan to avoid that:"],"source":{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-BASICS"}},{"code":"EXPLAIN ANALYZE SELECT four, unique1 FROM tenk1 WHERE four BETWEEN 1 AND 3 AND unique1 = 42;\n                                                              QUERY PLAN\n----------------------------------------------------------------------------------------------------------------------------------\n Index Only Scan using tenk1_four_unique1_idx on tenk1  (cost=0.29..6.90 rows=1 width=8) (actual time=0.006..0.007 rows=1.00 loops=1)\n   Index Cond: ((four \u003e= 1) AND (four \u003c= 3) AND (unique1 = 42))\n   Heap Fetches: 0\n   Index Searches: 3\n   Buffers: shared hit=7\n Planning Time: 0.029 ms\n Execution Time: 0.012 ms","paragraphs":["Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.","The “ Index Searches ” line is also useful with B-tree index scans that apply the skip scan optimization to more efficiently traverse through an index:"],"source":{"label":"PostgreSQL 18.6 · using-explain","path":"using-explain.html","sha256":"60040c30180093418a0affe56dd27dff9df2504b705b38039589e458bf5c31ed","url":"/docs/18/using-explain.html#USING-EXPLAIN-ANALYZE"}}],"title":"Examples from this manual build"},{"paragraphs":["Determine which direction to scan the index in based on the plan's scan direction and the current direction of execution.","We reach here if the index only scan is not parallel, or if we're serially executing an index only scan that was planned to be parallel.","If no run-time keys to calculate or they are ready, go ahead and pass the scankeys to the index AM.","We can skip the heap fetch if the TID references a heap page on which all tuples are known visible to everybody. In any case, we'll use the index tuple not the heap tuple as the data source.","Note on Memory Ordering Effects: visibilitymap_get_status does not lock the visibility map buffer, and therefore the result we read here could be slightly stale. However, it can't be stale enough to matter."],"title":"Executor implementation notes"},{"code":"case T_IndexOnlyScan:\n\t\t\tpname = sname = \"Index Only Scan\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"Index Only Scan","label":"Index Only Scan"}],"title":"EXPLAIN labels in this source build"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
