Why this matters
DBs may return rows in arbitrary order; explicit ordering ensures repeatable behavior.
Always specify ORDER BY when the processing logic relies on a particular order.
DBs may return rows in arbitrary order; explicit ordering ensures repeatable behavior.
Side-by-side examples engineers can pattern-match during review.
$rows = $pdo->query('SELECT * FROM events')->fetchAll();$rows = $pdo->query('SELECT * FROM events ORDER BY occurred_at DESC')->fetchAll();SELECT * FROM tSELECT * FROM t ORDER BY created_at DESCFrom 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.