Sitemap

Member-only story

How Database Indexes Work (In Simple Words)

Index table pointing to database table

When you run a database query, you want results as fast as possible. But without optimization, databases often need to scan every row to find what you’re looking for. This process can be painfully slow, especially for large tables.

Indexes can help with that. They work like a table of contents in a book — helping the database jump directly to the right place instead of flipping through every page.

Imagine you have a users table with 1 million records, and you need to find a user by email:

SELECT * FROM users WHERE email = 'alice@email.com';

Without an Index (Slow Query)

  • The database starts from the first page and checks every row, one by one.
  • If the record is stored towards the end, the database has to scan the entire table before finding it.

This is called a full table scan. It is slow because databases store data in pages.

What is a Page in a Database?

A page is a fixed-size block of memory (usually 8 KB or 16 KB) that holds multiple rows.

When a database fetches data from disk, it does not retrieve a single row — it loads an entire page into memory.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Databases

Published in Databases

“Databases” is a publication dedicated to deepening your understanding of databases. From ACID principles to performance tuning, indexing and query optimization, we break down database concepts in a simple, practical way.

Sergey Egorenkov
Sergey Egorenkov

Written by Sergey Egorenkov

Senior Software Engineer. Writing about software development with deep insights & real-world experience. You can reach out to me via email: egsesmail@gmail.com.

Responses (1)

Write a response

well explained on the databse indexing especially for the one that not familiar with it. i learned alot from it. thanks sergey.