To optimize a query, we need to know exactly where this query's performance bottleneck is, is it consuming too much CPU, or does it require too many IO operations? To be able to understand this information clearly, in MySQL 5.0 and the MySQL 5.1 official version can be very easy to do, that is, through the Query Profiler function.
MySQL's query Profiler is an easy-to-use Query diagnostic analysis tool that allows you to get a query that consumes a variety of resources throughout the execution, such as Cpu,io,ipc,swap, and the PAGE faults,c that occurs. Ontext Switche and so on, you can also get the position of each function in the source file called by MySQL during the Query execution.
After obtaining the profile, you can get a Query based on the query_id in the profile, taking 13 as an example
Show profile Cpu,block io for query 13;
MySQL built-in Profiling performance analysis tool