phpMyAdmin - Query Execution Time

前端 未结 4 1108
谎友^
谎友^ 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: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.

提交回复
热议问题