SQL B-tree, Composite, and Covering Indexes/Design for equality then range

Put equality columns first in many B-tree cases.

Section: Create index patterns

Design for equality then range

sql
sql
-- Often effective
INDEX (tenant_id, status, created_at)

-- Query
WHERE tenant_id = ? AND status = ? AND created_at >= ?
Explanation

A strong general pattern is equality predicates first, then range or ordering columns.

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
PostgreSQL covering index with INCLUDE
Store extra columns for index-only scans.
OpenIn sheetsqlsame section
Support ORDER BY with an index
Avoid expensive sorts when possible.
Example covering query
Query only indexed columns when possible.