Add a basic B-tree index to speed lookups.

Section: Indexes and Constraints

Create index

sql
sql
CREATE INDEX idx_orders_customer_id ON orders (customer_id);
Explanation

See summary for usage details.

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 Indexes and Constraints
Create index concurrently
Build an index with reduced write blocking.
OpenIn sheetsqlsame section
Create partial index
Index only a subset of rows.
OpenIn sheetsqlsame section
Create unique index
Enforce uniqueness with an index.
OpenIn sheetsqlsame section
Create expression index
Index an expression for case-insensitive lookups.
OpenIn sheetsqlsame section
Create GIN index on JSONB
Accelerate JSONB containment queries.
OpenIn sheetsqlsame section
Drop index
Remove an index that is no longer needed.
OpenIn sheetsqlsame section