Skip to main content

Database Indexing Simulator - Learn How Indexes Speed Up SQL Queries

Database Indexing

See how indexes speed up queries by avoiding full table scans

users table10 rows
idemailagecity
1alice@example.com28New York
2bob@example.com35Los Angeles
3carol@example.com42Chicago
4david@example.com31Houston
5emma@example.com28Phoenix
6frank@example.com45New York
7grace@example.com29San Diego
8henry@example.com38Dallas
9ivy@example.com33Chicago
10jack@example.com28Austin
Indexes

Add indexes to columns to speed up queries on those columns.

email
age
city
Query
SELECT * FROM users WHERE email = 'emma@example.com'
0
Queries Run
0ms
Total Time
0
Index Hits

How Database Indexes Work

Without Index (Full Table Scan)

The database must check every row in the table to find matches. Slow for large tables!

With Index (Index Seek)

The index acts like a book's index - the database jumps directly to matching rows. Much faster!

When to Create an Index:

  • • Columns used frequently in WHERE clauses
  • • Columns used in JOIN conditions
  • • Columns used for sorting (ORDER BY)
  • • High-cardinality columns (many unique values)

Understanding Database Indexes

How Indexes Work

B-Tree Structure: Most common index type. Like a book's index - sorted for fast lookup.
Index Seek: With an index, the database jumps directly to matching rows (O(log n)).
Full Table Scan: Without an index, every row must be checked (O(n)).

Index Types

Single-Column: Index on one column. Great for WHERE clauses on that column.
Composite: Index on multiple columns. Order matters! (A, B) ≠ (B, A).
Unique: Enforces uniqueness and provides fast lookups (emails, usernames).

💡 When to Index

✅ Good for Indexing

  • • Columns in WHERE clauses
  • • JOIN columns (foreign keys)
  • • ORDER BY / GROUP BY columns
  • • High cardinality (many unique values)

❌ Avoid Indexing

  • • Small tables (<1000 rows)
  • • Low cardinality (few unique values)
  • • Frequently updated columns
  • • Columns rarely used in queries

⚠️ Index Trade-offs

  • Storage: Indexes use additional disk space
  • Write Performance: INSERTs/UPDATEs are slower (index must be updated)
  • Maintenance: Indexes can become fragmented over time
  • Over-indexing: Too many indexes can hurt more than help