Why this matters
Avoids unnecessary DB load and latency.
Deduplicate identical queries within a request; reuse previously fetched data or preload in a single query.
Avoids unnecessary DB load and latency.
Side-by-side examples engineers can pattern-match during review.
foreach ($items as $i) { $p = loadProduct($i['product_id']); } // reloads same product many times$ids = array_unique(array_column($items, 'product_id'));
$products = loadProductsByIds($ids); // one queryinside loop SELECT ...bulk load then map by idFrom 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.