SQL Indexing and Performance/Use a covering index pattern

Create an index that supports filtering and ordering efficiently.

Section: Index Strategy

Use a covering index pattern

sql
sql
CREATE INDEX idx_orders_customer_created
ON orders (customer_id, created_at);
Explanation

Composite indexes can satisfy multiple parts of a query pattern.

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 Index Strategy
Index a common lookup column
Speed up frequent equality or range predicates.
OpenIn sheetsqlsame section
Avoid wrapping indexed columns in functions
Preserve index usability in predicates.
OpenIn sheetsqlsame section
Explain a query
Inspect the execution plan for a SELECT statement.
Use keyset pagination
Paginate by a stable cursor instead of a large OFFSET.
Find duplicate business keys
Detect repeated values that should be unique.
Explain with runtime stats
Run a query and collect timing or actual row information where supported.