Index Types
MySQL supports several index types: B-Tree (default, for range queries), Hash (exact match only, MEMORY engine), Full-Text, and Spatial. Choosing the right type matters for performance.
MySQL supports several index types: B-Tree (default, for range queries), Hash (exact match only, MEMORY engine), Full-Text, and Spatial. Choosing the right type matters for performance.
-- B-Tree index (default)
CREATE INDEX idx_email ON users (email);
-- Unique index
CREATE UNIQUE INDEX idx_username ON users (username);
-- Composite index
CREATE INDEX idx_status_date ON orders (status, created_at);
Composite indexes work for queries that filter on the leftmost columns.