LightMySky
En anglais

Indexes: B-Trees and the Cost of a Lookup

An index is a second structure that makes some lookups cheap and every write more expensive. Most are B-trees, whose wide nodes suit a disk that reads a page at a time, and whose ordering also serves ranges and sorts.

Commence ce sujetPas besoin de compte. La progression est enregistrée dans ce navigateur.

Ce que l'enfant saura faire ensuite

  • Say which of several queries an index on a given column would help
  • Explain why B-tree nodes are wide rather than binary
  • Name the costs an index adds to inserts, updates and storage

1 · Lis

Like the binary search tree that kept smaller values left and larger values right, an index is a second structure beside the table that keeps one column in order. It lists the values with pointers to the rows. A query that filters or sorts on that column can use the list instead of reading the whole table.

Most indexes are B-trees, which generalize the binary search tree you just met: each node holds about one disk page of keys, so a single read brings many keys. Wide nodes keep the tree shallow, and the stored order also speeds up ranges and sorting.

Try it together

A shop table has an index on email. A lookup of one email address uses the index. A filter on age ignores it, because no index covers age.

Every insert, update, and delete must update each index as well, and each index needs storage. Index the columns your frequent queries use, and leave the rest alone.

An index buys cheap lookups on one column and charges you on every write.

2 · Regarde

En anglais

Sans écran

Imprimer une fiche d'exercicesFormat A4, avec une page de corrigés pour les adultes. Sans écran, sans internet.

Où se situe ce sujet

Puis s'entraîner

8 questions attendent derrière cette leçon, chacune avec sa réponse expliquée. Chaque réponse nourrit le ciel : les étoiles s'allument à mesure qu'elles sont apprises, et pâlissent quand vient le moment de revenir.

Commence ce sujet