Mybatis-plus批量插入、批量修改数据saveBatch等速度缓慢

[转]Mybatis-plus批量插入、批量修改数据saveBatch等速度缓慢

Arebirth博客园: 原文链接

背景

使用mysqlPlus. 不管是updateBatch, 还是saveBatch, 800条左右的数据,
耗时都超过1s以上

尝试更改每次批量处理的数量, 比如:

super.updateBatchById(list,1000);
  • 1

如果不传第二个参数, mysqlPlus默认是1000. 这个根据调整, 发现低于1000, 耗时增加,15002500ms左右, 因为sql分多次执行, 中间IO请求的耗时比较大.
设置为1000(因为总共测试数据都没有1000, 所以没有尝试更大的值), 为900ms到1200ms左右.

这时间太久了,在网上找办法.

处理

最后发现在sql链接后追加: rewriteBatchedStatements=true. 再次尝试, 已经缩减到100ms!

 url: jdbc:mysql://localhost:3306/zgd?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=true

  • 1
  • 2

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Dengrz/article/details/121606325