MySQL5.7收集表统计信息时对该表上增删改查的影响

先说下结论:

收集统计信息期间对该表上DML和select的影响:结论是会影响DML,select不影响,并不是整改analyze过程都影响,大概影响1/3 analyze table时间。

官方文档说明:

https://dev.mysql.com/doc/refman/5.7/en/analyze-table.html 中有一段话对analyze table行为做了说明,如下:

During the analysis, the table is locked with a read lock for InnoDB and MyISAM.

ANALYZE TABLE removes the table from the table definition cache, which requires a flush lock. If there are long running statements or transactions still using the table, subsequent statements and transactions must wait for those operations to finish before the flush lock is released. Because ANALYZE TABLE itself typically finishes quickly, it may not be apparent that delayed transactions or statements involving the same table are due to the remaining flush lock.

测试过程:

使用sysbench压测也验证了确实会受影响:总共耗时1分23秒,其中23左右增删改完全受影响

/usr/bin/sysbench /usr/share/sysbench/oltp_read_write.lua --table_size=200000000 --db-driver=mysql --tables=1 --threads=2 --time=900 --mysql-host=192.168.30.11 --mysql-user=root --mysql-port=3306 --mysql-password=1234 --report-interval=1 run 

开启压测的过程中,执行收集表统计信息的命令

image.png

观察到在收集统计信息过程中TPS突然变为0

image.png

期间show processlist中观察到analyze table和压测过程中,analyze table一直为system lock状态:

再次使用read_only脚本测试,并没有发现tps降为0的现象。

/usr/bin/sysbench /usr/share/sysbench/oltp_read_only.lua --table_size=200000000 --db-driver=mysql --tables=1 --threads=2 --time=900 --mysql-host=192.168.30.11 --mysql-user=root --mysql-port=3306 --mysql-password=1234 --report-interval=2 run

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值