What is a covering index, and when does it help?
Sketch your own answer first, then compare it with the one below.
A strong answer
A covering index contains every column a query needs. The engine answers from the index alone and never visits the table page for each matching row. That saves a random read per row, which is the largest cost of a lookup that returns many rows.
The index gets wider because it stores the extra columns. It uses more space and makes writes to those columns touch the index too.
A good answer says to cover the hot, narrow queries, and not to widen an index to cover everything. It also notes that engines check that the index entry is visible to the reader, which can still require a table visit.
Sources
- PostgreSQL Global Development Group (2024). Index-Only Scans and Covering Indexes.