How to check mySQL query speed?

I have a choice and a request as shown below ...

$sql = "SELECT * FROM notifications WHERE to_id='".$userid."' AND (alert_read != '1' OR user_read != '1') ORDER BY alert_time DESC"; $result = mysql_query($sql); 

How to check the deadline for the request?

+4
source share
4 answers

There is a MySQL profiling system variable that is created in the INFORMATION_SCHEMA database for your specific session. See code below:

 mysql> set profiling=1; 

Just execute the query ... the query execution session will be saved to INFORMATION_SCHEMA .

 mysql> select count(*) from client where broker_id=2; 

Once the request is complete, simply run the following line:

 mysql> show profiles; 

which shows the total query execution time. Just execute and provide the request id as shown below to get the execution / speed of your request.

mysql> show profile for query 1;

+9
source

use the php microtime () function before and after mysql_query, and then compare the results.

 $time1 = (int) microtime(); $result = mysql_query($sql); $time2 = (int) microtime(); echo ($time2 - $time1); 

(if you use microtime (true) - which returns a floating point number, you will get fewer points)

+2
source

If you run the query from the mysql console, the speed will be displayed immediately after the query is launched.

+1
source
0
source

Source: https://habr.com/ru/post/1309318/


All Articles