Skip to main content

Indexing and Query Optimization

Index Basics

0:00
LearnStep 1/2

Index Basics

Database Indexes

An index is a data structure that speeds up data retrieval at the cost of storage and write performance.

Book Analogy

Index Structure

Index Types

TypeBest ForExample
B-TreeRange queries, equalityMost common
HashEquality onlyWHERE id = 5
Full-textText searchSearch engines
BitmapLow cardinalityGender, Status

Creating Indexes

sql

Trade-offs

  • Pros: Faster SELECT queries
  • Cons: Slower INSERT/UPDATE/DELETE, extra storage