Are Your Indexes Aligned with Query Paths?¶
Type: DeepDive
Category: Performance
Audience: Engineers optimizing specific endpoints, heavy queries, or complex filters
đ What This Perspective Is Really About¶
Not all indexes are equal.
And not all queries deserve them.
This perspective asks:
- Is this query actually using an index?
- Is the index ordered correctly for this filter + sort?
- Are your composite indexes aligned with query predicates?
â ď¸ Typical Pain Points¶
- N+1 joins on non-indexed foreign keys
- Composite indexes where predicate order doesnât match usage
- Queries filtered on
LOW_CARDINALITY = ?
killing selectivity - Indexes built for legacy queries now unused
- Missed use of
covering indexes
for heavy endpoints
â Good Index-to-Query Alignment¶
- Start from query logs / heatmaps â identify hot paths
- Run
EXPLAIN
to verify index hitsânot guess - Structure composite indexes to match most-selective predicates first
- Consider filtered indexes when full coverage isnât needed
- Drop dead indexes proactively to reduce bloat and conflict
đ§ Core Principle¶
Youâre not designing a schema.
Youâre designing query execution under pressure.
â FAQ¶
-
Q: Our queries seem fast. Is that enough?
A: Until your dataset grows or cache misses spike. -
Q: Canât the DB just figure it out?
A: It tries. But your structure limits its options.