On this page
  1. CREATE INDEX
  2. Syntax & Overview
  3. Notes & Best Practices
  4. Example

CREATE INDEX

Prev: `CREATE TABLE` | Up: clauses | Next: `EXPLAIN`
Rel: clauses, SQL Query Execution Lifecycle
Ref: PostgreSQL — SQL Commands
Tags: #public #databases #sql #clauses #tier/core


Syntax & Overview

CREATE INDEX idx_orders_user_status ON orders (user_id, status);

Creates a B-Tree (or GIN/GiST/partial) index to accelerate lookups and sorts.

Notes & Best Practices

Example

CREATE INDEX idx_orders_user_created
ON orders (user_id, created_at DESC)
WHERE status = 'paid';

Linked from

Related notes