Database Indexing Explained

What is Database Indexing?

An index is a data structure that improves query speed at the cost of additional writes and storage.

Index Types

Creating Indexes

-- Single column
CREATE INDEX idx_user_email ON users(email);

-- Composite index
CREATE INDEX idx_user_name_email ON users(name, email);

-- Unique index
CREATE UNIQUE INDEX idx_user_username ON users(username);

When to Use Indexes

When NOT to Use Indexes

Share This