mysql truncate 的问题


问题是微信群里一伙计提的

 

`mysql truncate 空表都需要3 4秒,要优化解决`

 

一开始觉得这莫名其妙,因为作这种操作的都是后台运维,不是实时的对外服务,运维又不差这3秒

 

其反应truncate表时 别的所有业务都阻塞

 

查看还真是个问题

 

https://dba.stackexchange.com/questions/147600/mysql-truncate-table-blocks-queries-in-other-databases

 

官方也有说明

 

https://dev.mysql.com/doc/refman/8.0/en/truncate-table.html

 

In MySQL 5.7 and earlier, on a system with a large buffer pool and innodb_adaptive_hash_index enabled, a TRUNCATE TABLE operation could cause a temporary drop in system performance due to an LRU scan that occurred when removing the table's adaptive hash index entries (Bug #68184). The remapping of TRUNCATE TABLE to DROP TABLE and CREATE TABLE in MySQL 8.0 avoids the problematic LRU scan.

 

解决方式是,测试用的表和线上的库隔离,或者升级mysql到8.0

 

原本 truncate操作 就不该在线上服务器发生

 

posted @ 2018-07-30 10:01  cclient  阅读(3157)  评论(0编辑  收藏  举报