phpMyAdmin - Query Execution Time

前端 未结 4 1054
谎友^
谎友^ 2021-01-22 23:58

When I execute a simple statement in phpMyAdmin like

SELECT *
FROM a

where \"a\" has 500\'000 rows, it gives me a time of a few milliseconds on

相关标签:
4条回答
  • 2021-01-23 00:28

    Besides splash21's answer, it is a good idea to use SQL_NO_CACHE when testing for execution time. This makes sure that you are looking at the real time to do the query, not just grabbing a cached result.

    SELECT SQL_NO_CACHE *
    FROM a
    
    0 讨论(0)
  • 2021-01-23 00:45

    phpMyAdmin automatically appends a LIMIT clause to your statement, so it has a smaller result set to return thus making it faster.

    Even if you need all 300,000 or 500,000 results then you should really use a LIMIT. Multiple smaller queries does not necessarily mean same execution time as a single big query.

    0 讨论(0)
  • 2021-01-23 00:50

    The displayed execution time is how long the query took to run on the server - it's accurate and comes from the MySQL engine itself. Unfortunately, the results have to then be sent over the web to your browser to be displayed, which takes a lot longer.

    0 讨论(0)
  • 2021-01-23 00:54

    No, phpMyAdmin is not telling the truth.

    Imagine you have a pretty big table, let's say a million rows. Now you do a select, something you know is going to take a while:

        SELECT * FROM bigTable WHERE value > 1234
    

    ...and PMA will report (after some waiting) that the query took some 0.0045 seconds. This is not the whole query time, this is the time of getting the first 25 hits. Or 50, or whatever you set the page size to. So it's obviously fast - it stops as soon as you get the first screenful of rows. But you will notice that it gives you this deceptive result after looong seconds; it's because MySQL needs to really do the job, in order to determine which rows to return. It runs the whole query, and then it takes another look and returns only a few rows. That's what you get the time of.

    How to get the real time?

    Do a count() with the same conditions.

        SELECT COUNT(1) FROM bigTable WHERE value > 1234
    

    You will get ONE row telling you the total number of rows, and naturally, PMA will display the exact time needed for this. It has to, because now the first page and the whole result means the same thing.

    0 讨论(0)
提交回复
热议问题