What if your database could find answers without opening every page?
Why Index-only scans mental model in PostgreSQL? - Purpose & Use Cases
Imagine you have a huge book with thousands of pages, and you want to find all pages mentioning a specific word. Without an index, you have to flip through every page, reading each one carefully.
Flipping through every page is slow and tiring. It wastes time and energy, especially if you only need a small piece of information. Mistakes happen when you lose your place or miss a page.
An index is like a detailed table of contents that tells you exactly which pages have the word you want. An index-only scan lets you find the information by looking just at the index, without opening the pages, making the search much faster.
SELECT * FROM big_table WHERE column = 'value';CREATE INDEX idx_column ON big_table(column);
SELECT column FROM big_table WHERE column = 'value'; -- may use index-only scanIndex-only scans let databases quickly answer queries by reading just the index, skipping the slower step of checking full data rows.
When an online store wants to quickly show all products in a category, index-only scans help find them instantly without searching every product detail.
Manual full scans are slow and error-prone.
Indexes act like a shortcut to find data quickly.
Index-only scans speed up queries by reading only the index.