-- 53_query_rewrite_tips.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: Common rewrites for performance.
-- Context: Retail bank example with customers, accounts, transactions, cards, loans.
-- Date: 2025-08-18
-- Notes:
--   * Safe to read; run on a development DB.
--   * Requires: CREATE privileges; some files may need superuser for extensions.
--   * Search path set to 'bank' schema for clarity.
SET search_path = bank, public;

-- Query rewrite: avoid SELECT * and push filters early
SELECT t.tx_id, t.amount
FROM bank.transactions t
WHERE t.amount > 10000
ORDER BY t.created_at DESC
LIMIT 100;
