简体   繁体   English

为什么phpmyadmin会比mysql命令行快得多?

[英]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. 我正在使用mariadb作为数据库引擎。

Query 1: 查询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 在mysql命令行中需要2.9秒,在phpmyadmin中需要0.1秒

Query 2: 查询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. 在mysql命令行中大约需要3.1秒,在phpmyadmin中大约需要0.9秒。

These timings are all taken from times that are automatically displayed after running the query. 这些计时都是取自运行查询后自动显示的时间。

Why would phpmyadmin be faster? 为什么phpmyadmin会更快? And why is the percentual difference in speed so big in phpmyadmin, but not in the mysql command line? 为什么速度百分比差异在phpmyadmin中如此大,而在mysql命令行中却没有?

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. 诸如phpMyAdmin之类的前端工具通常在LIMIT子句中装订,以便对结果进行分页,而不会使浏览器或应用程序在大型表上崩溃。 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. 当我将数据上传并插入到现有表中时,只是对大约1800万条记录的常规简单插入语句,我认为这很大程度上取决于您的设置和硬件。 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进行微调以使其在硬件上获得最佳性能,我花了一些时间才能远程完成该工作,因此决定在服务器中以简单的命令行上传。 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. Phpmyadmin,一次中断约500行,并且确实一次又一次地发送查询,因此连接不会超时。 It does the download and upload by chunks. 它按块进行下载和上传。 While phpmyadmin took about > 10 minutes to do the job, the command line was inmediate. 尽管phpmyadmin花费了大约10分钟以上的时间来完成这项工作,但命令行是中间的。

Whatever time took to read and upload the same SQL import file, it was several times slower phpmyadmin with timeout problems. 无论读取和上传相同的SQL导入文件花了什么时间,phpmyadmin都比超时慢了好几倍。 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. 它与很多因素有关,例如内存和最大变量等php.ini设置,http服务器设置(apache设置与带有php7-fastcgi参数的nginx等等)甚至是php版本也很重要,因为phpmyadmin可以完美地与某些版本,有时无法与其他人一起使用。 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. phpmyadmin非常适合详细信息,少量导入和导出以及快速修复,但是浏览器位于中间,因此我想直接数据输入输出总是更好,更快。 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. 那是我的卑鄙建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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