Skip to content

Instantly share code, notes, and snippets.

@staabm
Last active December 12, 2015 01:18
Show Gist options
  • Save staabm/4690326 to your computer and use it in GitHub Desktop.
Save staabm/4690326 to your computer and use it in GitHub Desktop.
mysql native profiling

see http://stackoverflow.com/questions/9947671/performance-difference-between-innodb-and-myisam-in-mysql

If you are using a relatively modern version of MySQL, run the following command before running the query:

set profiling = 1;

That will turn on query profiling for your session. After running the query, run

show profiles;

That will show you the list of queries for which profiles are available. I think it keeps the last 20 by default. Assuming your query was the first one, run:

show profile for query 1;

You will then see the duration of each stage in running your query. This is extremely useful for determining what (e.g., table locks, sorting, creating temp tables, etc.) is causing a query to be slow.

Example results

'continuing inside routine', '0.000005'
'Opening tables', '0.000003'
'init', '0.000005'
'optimizing', '0.000004'
'statistics', '0.000018'
'preparing', '0.000006'
'executing', '0.000001'
'Sending data', '0.000005'
'end', '0.000001'
'query end', '0.000001'
'closing tables', '0.000003'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment