MySQL不同插入方式性能对比实验

最近负责的项目需要数据同步入库MySQL,为了测速那种入库方式效率比较高,为此进行了以下的对比实验,在此记录一下

实验表单数据格式


实验代码

共三种方法对比

mutiSqlInsert:

一条一条插入,最后一次提交

singleSqlInsert:

用for循环拼接好插入sql,一次执行

executeBatchInsert:

使用MySQL提供的方法executeBatch(),同样使用一次提交

实验结果

1W条数据插入

mutiSqlInsert

singleSqlInsert

executeBatchInsert

10W条数据插入

mutiSqlInsert

singleSqlInsert

executeBatchInsert

2000条数据插入(当前kafka设置的单次最大拉取数为2000)

Kafka配置截图

mutiSqlInsert

singleSqlInsert

executeBatchInsert

结论

在一次性拉取数据较少时,mutiSqlInsert和executeBatchInsert的性能相差不大

当一次性插入数据非常多时,比如10W条,singleSqlInsert的性能会急剧下降,甚至不如mutiSqlInsert

关于10W条数据插入时singleSqlInsert的性能会急剧下降的原因,参考此文
https://blog.csdn.net/Tom_sensen/article/details/127922964

相关推荐
GreatSQL14 分钟前
优化GreatSQL日志文件空间占用
数据库
还有几根头发呀15 分钟前
MySQL事务深度解析:ACID特性、隔离级别与MVCC机制
数据库
morris13120 分钟前
【redis】发布订阅
数据库·redis·缓存·发布订阅
LCY13333 分钟前
django 运行时仅显示500 但是不提示其他内容 如何令其显示更多错误信息
数据库·django·sqlite
磨十三33 分钟前
Linux---sqlite3数据库
linux·数据库·sqlite
LCY13336 分钟前
django自动添加接口文档
数据库·django·sqlite
黄同学real1 小时前
解决Windows版Redis无法远程连接的问题
数据库·windows·redis
罗念笙1 小时前
MySQL InnoDB引擎中的聚簇索引和非聚簇索引有什么区别?
数据库
阿杰来学编程2 小时前
数据库约束
数据库·mysql
JeffreyGu.2 小时前
Oracle中In和Exists区别分析
数据库·oracle