### Index Only Scan
![[assets/ex_indexonlyscan.png|256]]
### The Explain Trace
```sql
-- Selecting only the indexed column
EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
SELECT id FROM animals WHERE id = 100;
```
```text
Index Only Scan using animals_pkey on public.animals (cost=1.29..5.30 rows=1 width=4) (actual time=1.067..1.068 rows=1 loops=1)
Output: id
Index Cond: (animals.id = 100)
Heap Fetches: 0
Buffers: shared hit=2 read=1
Planning Time: 1.113 ms
Execution Time: 1.084 ms
```
---
- **Description**: Scans an index without needing to access the table heap (unless rows are not all-visible).
- **Performance**: Extremely efficient as it avoids random heap I/O.
- **Factors**: Visibility map status, index size, and selectivity.
- **Cost**: `index cost + cpu_index_tuple_cost * number of index entries`
![[assets/ex_index_only_scan.svg|256]]
- **Workloads**:
- [[Workloads/IO/DataFile/DataFileRead|IO: DataFileRead]]
- [[Workloads/LWLock/Buffers/BufferContent|LWLock: BufferContent]]
- [[Workloads/LWLock/Buffers/BufferMapping|LWLock: BufferMapping]]
- **Operates on**: [[Structures/Index|Index]]