【问题标题】:Database query execution time数据库查询执行时间
【发布时间】:2021-08-17 00:18:16
【问题描述】:

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

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

然而,

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

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)


谁能给我解释一下,为什么会这样,就像batchcache。我不知道为什么会这样?提前致谢。

【问题讨论】:

  • 可能是套现,但是看看每一个的执行计划,看看你能不能找到什么有趣的东西
  • 尝试reset query cache; 并再次运行select count(*) from result where id &lt; 600000;。这应该可以解释为什么它跑得更快

标签: mysql sql caching


【解决方案1】:

id 950000 to 1000000 插入多行错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 2016-01-13
    • 2011-07-19
    • 2016-02-04
    • 1970-01-01
    相关资源
    最近更新 更多