Organize a route to the data
A database index is a structure that can help locate records without examining every row. A common tree-based index organizes keys so a database can narrow its search in stages. The useful key depends on the questions being asked. An index on one field does not automatically help every filter, ordering or combination of conditions.
Imagine a lending catalogue
Hypothetical example: a catalogue contains titles, authors and shelf locations. A reader asks for every item by one author. An author index could lead to matching entries directly. A request for all items on every shelf may gain little from the same route, because most records are needed anyway.
Account for the extra structure
An index occupies storage and must remain consistent as relevant records change. More indexes can increase the work required for writes. A database optimizer chooses an execution plan and may decide that scanning is preferable for a particular query. The useful question is therefore whether an index helps a real workload enough to justify its cost. Look at representative queries and changing data, rather than treating the presence of an index as proof of good performance. A plan explains a route; measured behavior under relevant conditions shows whether that route is useful.
Reference: Microsoft: Index architecture and design guide.
Continue reading
Permission with a boundary