Why this matters
Eliminates full scans and reduces latency at scale.
Index columns used in filters/joins/sorts; validate plans for slow queries and add composite indexes as needed.
Eliminates full scans and reduces latency at scale.
Side-by-side examples engineers can pattern-match during review.
SELECT * FROM tx WHERE user_id = ? ORDER BY created_at DESC-- create index (user_id, created_at DESC)
CREATE INDEX idx_tx_user_created ON tx(user_id, created_at DESC);WHERE email = ? -- no indexCREATE INDEX idx_user_email ON users(email)From the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.