0
Challenge · 85CS Fundamentals

Indexing and when it hurts

DBMSused in ~90% of apps

Everyone says an index makes queries faster. The interview question is the other half, which is what an index costs and when adding one makes things worse. That half is where the marks are.

Core idea. An index is a sorted copy of one or more columns with pointers back to the rows. It turns a full scan into a lookup, and in exchange every write has to update it and the query planner may still refuse to use it.
Playground, this isn't a screenshot
tick the behaviours an item needs
with inheritance
class PlainItem
One class per combination. Three behaviours need 8 classes, and a fourth needs 16.
with composition
traits: []
One item, a list of behaviours. Three behaviours need 3 functions, and a fourth needs 4.

Inheritance grows as two to the number of behaviours. Composition grows as the number of behaviours.

↑ play a little first, then dig in