0PricingLogin
SQL Interview Prep · Lesson

Covering Indexes and Index-Only Scans

Including columns so a query never touches the table heap.

Recalling the Heap Fetch

Earlier you learned that a normal B-Tree stores only the indexed columns plus a row pointer, so after the index finds matches the engine still hops to the table to read the other columns. That hop is the heap fetch, and it is the cost a covering index is designed to eliminate.

Interviewers ask about covering indexes to see whether you understand why an index can fully answer a query without touching the table.

What 'Covering' Means

An index covers a query when every column the query needs, in SELECT, WHERE, ORDER BY and GROUP BY, is present in the index itself.

When that holds, the engine reads only the index and never visits the table. PostgreSQL calls this an Index-Only Scan; SQL Server and others call it a covering index. The payoff is fewer page reads and faster queries.

All lessons in this course

  1. B-Tree Indexes and How They Help
  2. Composite Index Column Order
  3. Covering Indexes and Index-Only Scans
  4. When Indexes Hurt: Writes and Selectivity
← Back to SQL Interview Prep