Database Optimization EXPLAIN Analysis Always run before optimizing. Read the output bottom-up. Key metrics to watch: - Seq Scan on large tables = missing index - Nested Loop with high row count = consider hash/merge join - Sort without index = add index on sort column - Rows estimated vs actual divergence = stale statistics, run Index Strategies B-tree (default, most cases) Use for: equality, range queries, sorting. Column order matters in composite indexes: put equality columns first, then range/sort columns. Partial Index (PostgreSQL) Use when queries always filter on a specific condition.…