SQL B-tree, Composite, and Covering Indexes/PostgreSQL covering index with INCLUDE

Store extra columns for index-only scans.

Section: Create index patterns

PostgreSQL covering index with INCLUDE

sql
sql
CREATE INDEX idx_orders_status_created_at_inc ON orders (status, created_at DESC) INCLUDE (total_amount, user_id);
Explanation

`INCLUDE` can help PostgreSQL serve some queries directly from the index when conditions are right.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Create index patterns
Create a single-column index
Index a common lookup column.
OpenIn sheetsqlsame section
Create a composite index
Index fields that are commonly used together.
OpenIn sheetsqlsame section
Design for equality then range
Put equality columns first in many B-tree cases.
OpenIn sheetsqlsame section
Example covering query
Query only indexed columns when possible.
OpenIn sheetsql1 tag match
Support ORDER BY with an index
Avoid expensive sorts when possible.