AdvancedPerformance & Indexes
Covering index: avoid heap fetch completely
The query
SQL
-- Query: get name, salary, dept for active engineers
-- Without covering index: index lookup + heap fetch (slower)
CREATE INDEX idx_emp_dept ON employees(dept_id, status);
-- WITH covering index (INCLUDE for non-search columns)
CREATE INDEX idx_emp_covering ON employees(dept_id, status)
INCLUDE (first_name, last_name, salary, job_title);
-- Now this query can use INDEX ONLY SCAN:
EXPLAIN (ANALYZE)
SELECT first_name, last_name, salary, job_title
FROM employees
WHERE dept_id = 3 AND status = 'active';
-- Should show: "Index Only Scan" with "Heap Fetches: 0"Note
“INCLUDE columns in PostgreSQL 11+ create covering indexes. Zero heap fetches = fastest possible read.