Why this matters
Reduces round-trips and lock contention; improves performance.
Prefer set-based SQL (DELETE/UPDATE with WHERE IN/JOIN) or chunked batches over per-row statements.
Reduces round-trips and lock contention; improves performance.
Side-by-side examples engineers can pattern-match during review.
foreach ($ids as $id) { $pdo->prepare('DELETE FROM t WHERE id=?')->execute([$id]); }$in = str_repeat('?,', count($ids)-1) . '?';
$sql = "DELETE FROM t WHERE id IN ($in)";
$pdo->prepare($sql)->execute($ids);loop + DELETEDELETE ... WHERE id IN (...)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.