Codacoda
Back to Academy

relational database

Indexing

A database index is a data structure that speeds up data retrieval at the cost of additional storage and write overhead. Without an index, the database must scan every row (full table scan). With a B-tree-like index, lookups become logarithmic. Indexes are critical for query performance on large tables.

Use Cases

  • Speeding up user lookups by email in an authentication system
  • Optimizing WHERE clause queries on frequently filtered columns
  • Accelerating JOIN operations by indexing foreign key columns
  • Trading slightly slower writes for dramatically faster reads on large tables

Visualization

BEFOREproductsidnameprice3Widget291Gadget495Doohickey152Thingamajig354Gizmo42
Speed:1x
Table 'products' with 5 rows, no index — finding id=4Step 1 / 7

Implementation

Output

Click "Run Code" to see output...