Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get time for MySQL result without showing result

I realized that using phpMyAdmin for testing the speed of queries might be dumb: it automatically applies a LIMIT clause.

I tried a certain query on a fairly large number of records (31,595) with a GROUP BY clause. phpMyAdmin, adding LIMIT 0, 200, took 0.1556 seconds to fetch the results.

I decided to try the same query from the command line without the LIMIT clause and it took 0.20 seconds. Great, so now I have the real time it takes for that query.

But the downside is I had to wait for 30,000+ records to print on the screen.

Is there a better solution?

EDIT: To clarify, I am looking for a way to suppress the screen output of a select query while still getting an accurate time for running the query. And I want it to be something that could be typed in and timed at any time (i.e. I don't want to have to tweak slow log settings to capture results).

like image 991
Buttle Butkus Avatar asked Oct 17 '25 17:10

Buttle Butkus


1 Answers

You could enclose your query in SELECT COUNT(1) to count the number of rows returned, without having all the rows printed out:

SELECT COUNT(1)
  FROM (
    <<you query goes here>>
) t;
like image 111
Przemyslaw Kruglej Avatar answered Oct 22 '25 08:10

Przemyslaw Kruglej