Rails: The Sharp Parts. An Index Is Not a Plan

add_index looks like a one-line fix for slow queries. It isn't. This article walks through the failure modes, proves each one with EXPLAIN on half a million rows, and shows how to build an index the optimizer will actually use.