Skip to content

Instantly share code, notes, and snippets.

@mesaque
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save mesaque/16aaeac190a3fb8af72a to your computer and use it in GitHub Desktop.

Select an option

Save mesaque/16aaeac190a3fb8af72a to your computer and use it in GitHub Desktop.
#First you need to active profiling on your mysql
set profiling = 1;
#run some queries and see the status
show profiles;
#after that you cant set the variable and see the query full details
SET @query_id = 1;
SELECT STATE, SUM(DURATION) AS Total_R,
ROUND(
100 * SUM(DURATION) /
(SELECT SUM(DURATION)
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = @query_id
), 2) AS Pct_R,
COUNT(*) AS Calls,
SUM(DURATION) / COUNT(*) AS "R/Call"
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = @query_id
GROUP BY STATE
ORDER BY Total_R DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment