I am testing and comparing execution times of queries with big result sets using the command line.
It takes too long to display the result set! Is there any way to see only the query execution time without waiting till all of the result set is displayed?
-
I guess you will need to define what "query execution time" means to you. Sending the result set to the client and processing it (e.g. formatting and displaying it on the terminal) might very well be a part of "execution". What is the purpose of this " testing and comparing"?mustaccio– mustaccio2020年06月04日 22:47:19 +00:00Commented Jun 4, 2020 at 22:47
-
I am testing how different indexes affect on same query execution speed, so I don’t need to take to consideration time that command line spends on displaying the result set.Andranik Markaryan– Andranik Markaryan2020年06月04日 23:42:40 +00:00Commented Jun 4, 2020 at 23:42
-
Execution plans should tell you that.mustaccio– mustaccio2020年06月05日 00:56:31 +00:00Commented Jun 5, 2020 at 0:56
-
which MySQL Version you are using ?JYOTI RAJAI– JYOTI RAJAI2020年06月05日 05:43:28 +00:00Commented Jun 5, 2020 at 5:43
-
is it ok to send output to file?NikitaSerbskiy– NikitaSerbskiy2020年06月05日 10:39:41 +00:00Commented Jun 5, 2020 at 10:39
1 Answer 1
Solution for Getting only Execution time of Query without printing result set :
Query :Select C1 , C2, C3 from Table where C3='1'; -- 40571 rows in set (0.079 sec)
Get Count of query :
Do :
Select count(*) from (Select C1 , C2, C3 from Table where C3='1') as X;
Time : 0.035 sec
Redirecting output to
/dev/null
:Do :
time mysql -u'user' -p'password' Database < query.sql > /dev/null
Time :
real 0m0.180s
user 0m0.112s
sys 0m0.005s
Using mysqlslap :
Do :
vi query1.sql // Addin the query.
mysqlslap -u'user' -p'password' --query="query1.sql" --delimiter=";" --concurrency=1 >> output.log
Time :
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
Benchmark
Average number of seconds to run all queries: 0.080 seconds
Minimum number of seconds to run all queries: 0.080 seconds
Maximum number of seconds to run all queries: 0.080 seconds
Number of clients running queries: 1
Average number of queries per client: 1
According to me ideal is 3rd solution using mysqlslap
-
Thank you for answer and sorry for late reply, I also prefer
mysqlap
solution, but I can't understand why execution time shown when running query in cmd mismatch time shown bymysqlslap
. I executed this queryselect * from test_users_s;
10 times in cmd, and got stable result: (0.019, 0.019, 0.019, 0.019, 0.019, 0.021, 0.020, 0.021, 0.019, 0.019), then I executed following commandmysqlslap -u root -p --create-schema="mysql_test" --query="select * from test_users_s;"
10 times and get this not stable results: (0,031, 0,031, 0,031, 0,015, 0,015, 0,031, 0,015, 0,032, 0,031, 0,016).Andranik Markaryan– Andranik Markaryan2020年06月29日 19:45:48 +00:00Commented Jun 29, 2020 at 19:45 -
Maybe I am doing smth wrong? Only when running query with mysqlslap with 10-20 iterations I get avg result near to result of cmd: Average number of seconds to run all queries: 0.018 seconds Minimum number of seconds to run all queries: 0.015 seconds Maximum number of seconds to run all queries: 0.031 seconds Number of clients running queries: 1 Average number of queries per client: 1Andranik Markaryan– Andranik Markaryan2020年06月29日 19:49:14 +00:00Commented Jun 29, 2020 at 19:49
-
In direct cmd prompt, you are already connected to server & when you frequently re-executed you get output from cache which why time is stable. But in mysqlslap there are so many other factors came in picture everytime new connection , querycache etc.JYOTI RAJAI– JYOTI RAJAI2020年06月30日 04:34:28 +00:00Commented Jun 30, 2020 at 4:34