We’ve found it useful to analyze a poorly performing query in two steps:
1. Find out whether your application is retrieving more data than you need. That
usually means it’s accessing too many rows, but it might also be accessing too
many columns. Fetching more rows than needed, Fetching all columns (*)
2. Find out whether the MySQL server is analyzing more rows than it needs.
In MySQL, the simplest
query cost metrics are:
• Execution time
• Number of rows examined
• Number of rows returned
All three metrics are logged in the slow
query log, so looking at the slow query log is one of the best ways to find queries that
examine too much data.
