AdvancedTopic 78 of 104Software & Computing

Indexing

Data structures such as B-trees speed up queries.

In depth

Indexes (B-tree, hash, bitmap, full-text) speed up searches by avoiding full table scans, at the cost of extra storage and slower writes. Use on columns in WHERE, JOIN and ORDER BY; composite indexes follow leftmost-prefix rule. EXPLAIN shows the plan.

Key points

  • Selectivity
  • Covering index
  • Index maintenance
Example

Adding an index on email turns a 1-second scan into a millisecond lookup.

Why it matters

Indexes speed up lookups by keeping sorted or hashed access paths to the data, so queries stay fast as tables grow.

Where this is used

  • Adding an index on the customer ID column to speed up order lookups.
  • Finding a row by serial number in a large inventory table.
  • Making a date range query on a log table fast enough for reports.

Frequently asked questions

What is Indexing?

Data structures such as B-trees speed up queries.

Why is it important to understand indexing?

Indexes speed up lookups by keeping sorted or hashed access paths to the data, so queries stay fast as tables grow.

What is the cost of an index?

Extra storage and slower writes, because the index must also be updated on every insert, update or delete.

What is a B-tree index?

A balanced tree index that supports both exact lookups and range queries efficiently on disk-based storage.

How is Indexing used in practice?

Typical applications include adding an index on the customer ID column to speed up order lookups, finding a row by serial number in a large inventory table and making a date range query on a log table fast enough for reports.

What should I learn before Indexing?

Study "Transactions and ACID" first (topic 77 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of Indexing?

Selectivity. Covering index. Index maintenance.

Can you give an example of Indexing?

Adding an index on email turns a 1-second scan into a millisecond lookup.

What comes after Indexing?

The next topic is "NoSQL databases", which builds directly on this one.

How difficult is Indexing?

It is classed as Advanced in Software & Computing (topic 78 of 104). It is an advanced topic. It assumes you are comfortable with the intermediate topics in Software & Computing.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics