Find expensive SQL
Start with statements that consume high total time, have high average latency, or sit on critical paths such as checkout, booking, reporting, and search.
SQL performance tuning
Good tuning identifies the SQL statements that affect real users, explains why they are expensive, and turns that evidence into safer changes to query shape, indexes, data access, or capacity.
Start with statements that consume high total time, have high average latency, or sit on critical paths such as checkout, booking, reporting, and search.
Use plans, row counts, scan type, join method, sort work, and temporary writes to understand where the database spends time.
Filter earlier, return fewer columns, avoid repeated lookups, simplify joins, and remove unnecessary sorting before scaling infrastructure.
Index candidates should match predicates, joins, ordering, and selectivity. A useful index lowers read cost without creating avoidable write overhead.
Compare before and after plans, staging behavior, lock risk, and production rollout impact before treating a tuning idea as complete.
Tuning one query can move pressure elsewhere. Connect SQL work to broader database optimization evidence.
Tuning workflow
Sort by workload cost, not the single slowest statement. Frequent medium-cost SQL can matter more than rare outliers.
Pick the change that directly addresses the observed cost: index, rewrite, pagination, batching, statistics, or capacity review.
This page covers broad SQL performance tuning. For PostgreSQL databases, continue to the PostgreSQL optimization path or the focused PostgreSQL slow query audit after the general tuning scope is clear.