简体   繁体   中英

Why would phpmyadmin be significantly faster than the mysql command line?

Everything is run on the same machine the database is on. These queries do the same thing in a different way. I'm using mariadb as the db engine.

Query 1:

SELECT p.* 
FROM users as u INNER JOIN votes ON u.Id=votes.UserId INNER JOIN posts as p ON p.Id=votes.PostId 
WHERE (SELECT MIN(u2.reputation) 
       FROM users as u2 INNER JOIN votes ON u2.Id=votes.UserId INNER JOIN posts as p2 ON p2.Id=votes.PostId 
       WHERE p2.Id=p.Id) >= {}
ORDER BY p.Id;

Takes about 2.9 seconds in the mysql command line, and 0.1 seconds in phpmyadmin

Query 2:

SELECT P.*
FROM posts as P 
    JOIN votes AS V on P.Id=V.PostId
    JOIN users AS U on V.UserId=U.Id
WHERE U.Reputation >={}
    AND P.Id NOT IN 
    (SELECT DISTINCT (P2.Id)
    FROM posts P2, votes V2,users U2
    WHERE P2.Id=V2.PostId
        AND V2.UserId =U2.Id
        AND U2.reputation < {})
ORDER BY P.Id;

Takes about 3.1 seconds in the mysql command line, and 0.9 seconds in phpmyadmin.

These timings are all taken from times that are automatically displayed after running the query.

Why would phpmyadmin be faster? And why is the percentual difference in speed so big in phpmyadmin, but not in the mysql command line?

Front-end tools like phpMyAdmin often staple on a LIMIT clause in order to paginate results and not crash your browser or app on large tables. A query that might return millions of records, and in so doing take a lot of time, will run faster if more constrained.

It's not really fair to compare a limited query versus a complete one, the retrieval time is going to be significantly different. Check that both tools are fetching all records.

Depending on the storage engine you're using, it is most probably the data is being loaded from a data cache and not a query cache. The time difference is too big, if you clean the cache and run the query again, you will notice the difference

While I was uploading and inserting data to an existing table, just regular simple insert statement on about 18 million records, I figure that much depends on your setup and hardware. Fine tuning phpmyadmin to for best performance on your hardware, it took me a while to do the job remotely, so decided to to a simple command line upload in the server. Phpmyadmin, breaks about 500 lines at a time, and does send the query again and again, several times, so the connection doesn't time out. It does the download and upload by chunks. While phpmyadmin took about > 10 minutes to do the job, the command line was inmediate.

Whatever time took to read and upload the same SQL import file, it was several times slower phpmyadmin with timeout problems. It has to do with many factors, php.ini settings such as memory and max variables, http server settings (apache settings differ from nginx with php7-fastcgi parameters and so on) even the version of php matters, since phpmyadmin works perfectly with some versions and sometimes doesnt work like it should with others. Better off using direct dump from command line if you do large xfer of data. phpmyadmin is great for details, small imports and exports, and quick fixes, but browser is in the middle, so I guess straight forward data input output is always better and much faster. So, to answer your question, is matter of settings, hardware and the job you are doing and how you are doing it. Thats my humble advice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM