An index stores search keys and row locations in a separate structure. Many relational databases use a B-tree family index to narrow the range level by level, then fetch matching rows.
The demo finds key 42 by taking the branch below 50 and then reaching its leaf. Indexes can speed reads but consume storage and add update work to writes.
When to use
Inspect the query plan and consider an index when repeated WHERE, JOIN, or sort queries are slow.