Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring actual MySQL query time

How can I measure the execution time of a query without measuring the time it spends waiting for a lock release etc? My only idea was to continuously measure same query and record the fastest time.

like image 900
Mikhail Avatar asked Jun 30 '12 14:06

Mikhail


People also ask

How can you check the performance of a query?

Use the Query Store page in SQL Server Management Studio In Object Explorer, right-click a database, and then select Properties. Requires at least version 16 of Management Studio. In the Database Properties dialog box, select the Query Store page. In the Operation Mode (Requested) box, select Read Write.

What is current time in MySQL?

MySQL CURRENT_TIME() FunctionThe CURRENT_TIME() function returns the current time. Note: The time is returned as "HH-MM-SS" (string) or as HHMMSS. uuuuuu (numeric). Note: This function equals the CURTIME() function.


2 Answers

Start the profiler with

SET profiling = 1; 

Then execute your Query.

With

SHOW PROFILES; 

you see a list of queries the profiler has statistics for. And finally you choose which query to examine with

SHOW PROFILE FOR QUERY 1; 

or whatever number your query has.

What you get is a list where exactly how much time was spent during the query.

More info in the manual.

like image 115
fancyPants Avatar answered Sep 30 '22 13:09

fancyPants


The accepted Answer is becoming invalid...

SHOW PROFILE[S] are deprecated as of MySQL 5.6.7 and will be removed in a future MySQL release. Use the Performance Schema instead; see http://dev.mysql.com/doc/refman/5.6/en/performance-schema-query-profiling.html

like image 31
Rick James Avatar answered Sep 30 '22 13:09

Rick James