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操作 就不該在線上服務器發生

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM