简体   繁体   English

从巨大的表中优化MySQL SELECT

[英]Optimizing MySQL SELECT from huge table

I'm doing regular 我经常做

SELECT * FROM sensor_data_1sec LIMIT 491160, 30

from this table: http://test.dev.brown.sk/sensor_data_1sec.zip 来自此表: http : //test.dev.brown.sk/sensor_data_1sec.zip

It tooks about 0.06s. 大约需要0.06s。 I think it is too much. 我觉得太多了。 MySQL server is on my PC with Intel Core i7, 8 GB RAM, Windows 7. MySQL服务器在装有Intel Core i7、8 GB RAM,Windows 7的PC上。

Take a look on phpMyAdmin: 看看phpMyAdmin: 在此处输入图片说明

Of course it took much little time when it is cached. 当然,缓存它的时间很少。 But is it possible to make it faster uncached? 但是有可能使其更快地被缓存吗?

Six hundredths (or two hundredths) of a second is fine. 百分之一秒(或百分之一秒)就可以了。 The basic rule is that a user shouldn't be kept waiting for too long and I generally put that at half a second. 基本规则是,用户不应等待太久,我通常将其等待半秒钟。

Is there something you may have acheived in that 0.06s that you're bothered about, had you known it was going to be that slow? 在您不知道它会这么慢的那段时间里,您可能会在0.06s的时间内实现某些目标吗? :-) :-)

As an aside, it's unwise to assume a particular order in a result set from a query with no ordering clause. 顺便说一句,从没有排序子句的查询中假设结果集中的特定顺序是不明智的。 It's also usually preferred to explicitly select columns rather than using * . 通常也更喜欢显式选择列而不是使用*

It's slow because off the deep scan. 这很慢,因为未进行深度扫描。 An large offset in the LIMIT is bad very bad, if you run an EXPLAIN you will see it needs a temporary table to handle this. LIMIT中的较大偏移量非常糟糕,如果您运行EXPLAIN,您将看到它需要一个临时表来处理此问题。 And this temporary is proberly disk based because it needs the memory off 491190 records. 而且此临时磁盘基于探针磁盘,因为它需要关闭491190条记录的内存。 So you are killing the MySQL performance now. 因此,您现在正在丧失MySQL性能。

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

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