Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 数据库查询执行时间_Mysql_Sql_Caching - Fatal编程技术网

Mysql 数据库查询执行时间

Mysql 数据库查询执行时间,mysql,sql,caching,Mysql,Sql,Caching,当我使用以下方法计算行数时,总共需要4分钟51.62秒 mysql> select count(*) from result where id < 1000000; +----------+ | count(*) | +----------+ | 0 | +----------+ 1 row in set (4 min 51.62 sec) mysql> select count(*) from result where id < 500000; +---

当我使用以下方法计算行数时,总共需要4分钟51.62秒

mysql> select count(*) from result where id < 1000000;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (4 min 51.62 sec)
mysql> select count(*) from result where id < 500000;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.14 sec)

mysql> select count(*) from result where id < 600000;
1 row in set (0.21 sec)

mysql> select count(*) from result where id < 700000;
1 row in set (0.28 sec)

mysql> select count(*) from result where id < 800000;
1 row in set (0.23 sec)

mysql> select count(*) from result where id < 900000;
1 row in set (0.26 sec)

mysql> select count(*) from result where id < 950000;
1 row in set (0.27 sec)

mysql> select count(*) from result where id < 1000000;
1 row in set (39.66 sec)


但是,

当我使用以下方法将行数计算为增加id时,总共需要41.05秒

mysql> select count(*) from result where id < 1000000;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (4 min 51.62 sec)
mysql> select count(*) from result where id < 500000;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.14 sec)

mysql> select count(*) from result where id < 600000;
1 row in set (0.21 sec)

mysql> select count(*) from result where id < 700000;
1 row in set (0.28 sec)

mysql> select count(*) from result where id < 800000;
1 row in set (0.23 sec)

mysql> select count(*) from result where id < 900000;
1 row in set (0.26 sec)

mysql> select count(*) from result where id < 950000;
1 row in set (0.27 sec)

mysql> select count(*) from result where id < 1000000;
1 row in set (39.66 sec)



谁能给我解释一下,为什么会这样,它就像批处理或缓存一样。我不知道为什么会这样?提前感谢。

id 950000到1000000插入多行错误

可能正在兑现,但请查看每个行的执行计划,看看是否可以找到任何有趣的内容重置查询缓存;并从id<600000的结果运行select count*;再一次这应该可以解释为什么它跑得更快