0 day streak
sql / intermediate
Snippet

Multi-Column Indexing for Multi-Filter Optimization

Composite indexes store sorted references across multiple columns. Structuring the index with the highest-cardinality equality filter column first significantly accelerates multi-condition filtering.

snippet.sql
sql
1
2
CREATE INDEX idx_orders_customer_date
ON orders (customer_id, order_date);
Breakdown
1
CREATE INDEX idx_orders_customer_date
Defines a new named database index structure on the target table.
2
ON orders (customer_id, order_date);
Specifies the column evaluation sequence, ordering first by customer ID and then by order date.