All lessons in Software Engineering: Programs, Systems, and Maintainable Software
Indexes and Query Plans
Choose an index from a query shape and compare measured plans without assuming every index helps.
40 minutes · Members lesson · preview
What you will learn
- Derive a candidate index from filters, ordering, and expected selectivity.
- Explain why an available index may not be chosen by the planner.
- Compare plans and measurements without confusing estimated cost with elapsed time.
A member-history query filters by member ID and returns the newest borrowing records. Scanning every loan row becomes expensive as history grows. An index can reduce the relevant search, but it also occupies space and adds work to writes. Choose it from the query and workload, not from the rule that every filtered column deserves an index.
This lesson separates the logical query result from the physical plan used to obtain it. Changing an index should preserve the result while changing the work required.