【发布时间】:2020-06-12 07:21:35
【问题描述】:
谁能解释一下为什么 DELETE 语句需要更多时间来执行?我们还没有创建任何 TRIGGER 或 CASCADE。当从 5.5 迁移到 8.0 时,我们开始注意到这个问题。是不是8.0参数调优的问题?
DELETE s FROM storefront s LEFT JOIN MASTER m ON m.userid=s.userid WHERE m.userid IS NULL
9 row(s) affected
Execution Time : 40.816 sec
Transfer Time : 0.001 sec
Total Time : 40.817 sec
同时,SELECT 语句只需要几毫秒。
SELECT s.userid FROM storefront s LEFT JOIN MASTER m ON m.userid=s.userid WHERE m.userid IS NULL
Total Time : 0.05 sec
任何帮助将不胜感激。我们有更好的服务器硬件和 16 GB 的 RAM。
这是 DELETE 语句的 PROFILING 信息。
It is CPU_user(19.046875 seconds) and CPU_system(43.156250 seconds) taking most of the time out of the total execution time 50.24 seconds ....
【问题讨论】:
-
两张表上都有索引吗?检查
EXPLAIN,看看这两个查询发生了什么。 -
请注意,上面两个语句对于 EXPLAIN 是相同的,而后面的语句只需要几毫秒。我怀疑锁争用。
-
SELECT 不需要在磁盘上写东西,而 DELETE 需要。
-
@Akina,40 秒似乎可以从磁盘中删除 9 条记录吗?
-
@Akina,当我们从 5.5 迁移到 8.0 时,我们开始注意到这个问题。这两个表都在 myISAM 上。我们已将 innodb_file_per_table 验证为 ON
标签: mysql database performance dml