What is Query Optimization?
The process of improving database query performance through indexing, query rewriting, and schema design techniques.
Query optimization starts with EXPLAIN ANALYZE to understand execution plans. Common optimizations include adding indexes on frequently filtered/joined columns, rewriting subqueries as JOINs, avoiding SELECT *, and using LIMIT for pagination.
Advanced techniques include partial indexes (index subset of rows), covering indexes (include all needed columns), materialized views (pre-computed results), query caching, and connection pooling. Regular ANALYZE ensures the query planner has current statistics.