Optimizing slow queries starts with analyzing the execution plan (EXPLAIN) to find the bottleneck, then applying targeted fixes — most commonly adding indexes, rewriting the query, and avoiding common anti-patterns. The biggest win is usually turning full table scans into index lookups.
Step 1: analyze with EXPLAIN
EXPLAIN ANALYZE
orders customer_id ;
