openskills.info
Course Preview

Database Indexing

Database indexing creates auxiliary data structures that speed up query lookups without scanning every row. Understanding index types, their storage trade-offs, and how the query planner uses them is essential to database performance tuning.

itDatabases and data storage

Database Indexing

A database index is a separate data structure that gives the query planner another way to find rows. Without a useful index, the database may inspect every row in a table. With one, it can navigate to a smaller set of candidates.

Think of an index as an ordered map from selected values to row locations. The map helps only when its structure matches the question. It also occupies space and must change when indexed data changes.

Why indexes exist

Tables are optimized to store complete rows. Queries often need a narrow slice of those rows:

  • one account by email address;
  • recent orders for one customer;
  • rows joined through a key;
  • the first ten events in a requested order;
  • values that must remain unique.

An index can reduce the work needed for those access patterns. It can support filtering, joins, ordering, and uniqueness enforcement. It does not make every query fast.

The query planner chooses an execution plan from the available access paths. An index is an option, not an instruction. The planner may prefer a table scan when a condition matches much of the table or when the estimated index work costs more.

The B-tree mental model

A B-tree is the default and most common index type in many relational databases. It keeps keys in order and supports equality, range, and ordered retrieval.

Imagine an index on orders.created_at. The database navigates through upper levels of the tree to a leaf range containing the requested dates. Leaf entries identify candidate rows. The database may then fetch full rows from the table.

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources