Database Index Type
Question
What is a composite index?
Hint
Column order in composite indexes matters for query optimization.
Explanation
A composite index (multi-column index) is an index on two or more columns. CREATE INDEX idx_name ON users(last_name, first_name). The column order matters — the index is most effective when queries filter on the leading columns. A query on last_name alone can use the index, but a query on first_name alone cannot (without a separate index). Composite indexes are useful for: 1) Multi-column WHERE conditions. 2) ORDER BY on multiple columns. 3) Covering indexes (index includes all queried columns). Choose column order based on query patterns and selectivity (most selective columns first).
Related Resources
Related Lessons
- Indexes
Learn indexes.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.