When you ask someone how to optimize SQL queries you will always get the answer
- enable the slow query log
- set the long-query-time to 1-2 seconds
- enable the logging of query which aren't using an index
- run
EXPLAIN
on the queries that are shown and optimize them with proper indexes
But how to understand what the EXPLAIN is telling you ?
I picked a query from the ORDER BY RAND article as they became interesting enough to show the different aspects of of a query. They contain:
- Sub-Queries
- Unions
- Special cases
- JOINs
- ORDER BY + LIMIT
If you want to understand how this query was developed, check the original article about …
[Read more]