covering index: An index that contains every column a query needs, so the database answers from the index alone — an index-only scan. A covering index contains every column a query needs. The database can answer the query from the index alone, without looking up the full rows in the table. This is called an index-only scan, and it is often much faster.
If a page lists a customer's orders with only the date, status and total, an index on (customer_id, created_at) that also includes status and total covers the query completely. PostgreSQL has an INCLUDE clause for those extra columns; in MySQL you add them to the index itself.
What should you keep in mind with covering index?
Use this for frequent, performance-critical queries, not for everything. Wider indexes take more space and slow down writes. Selecting only the columns you need, instead of SELECT *, is what makes covering indexes possible in the first place.
What does an example of covering index look like?
CREATE INDEX idx_cover ON orders (user_id) INCLUDE (total, status);
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and schedule