首页 > 其他分享 >mybatis-plus批量插入性能提升

mybatis-plus批量插入性能提升

时间:2022-10-13 17:33:27浏览次数:41  
标签:批量 性能 插入 plus userInfo mybatis 1000

最近在引入mybatis-plus后发现其批量插入的性能不高,所以与mybatis的<foreach/>标签生成的sql插入性能做了对比

测试环境:

  1. 6核12线程,16g内存
  2. 本地数据库,没有网络传输
  3. 数据库字段7个,没有超过32位的长字符串
  4. 超过1000数据量的,按1000分批插入
  5. 开启事务

首先给出结论:

  1. 小数据量时(小于1000),性能相差不大。
  2. 数据库url未加rewriteBatchedStatements=true时,mybatis性能高于mybatis-plus,大于5000数据量时,差不多是4倍的差距
  3. 数据库url加rewriteBatchedStatements=true时,mybatis-plus性能高于mybatis,大于5000数据量时,差不多是1.5倍差距

所以增加配置后,mybatis-plus的批量插入性能不低,基本无代码入侵,也不会影响已有的代码,其对单表的操作很方便,可以考虑引入使用。

1、性能测试对比

测试代码如下:

    @Transactional
    @Override
    public void batchInsert(Integer total, String type) {
        List<UserInfo> list = new ArrayList<>(total);
        Date date = new Date();
        for (int i = 0; i < total; i++) {
            UserInfo userInfo = new UserInfo();
            userInfo.setName("" + i);
            userInfo.setPhone("13266665555");
            userInfo.setCreateTime(date);
            userInfo.setIsDelete(1);
            userInfo.setFirstPinyin("" + i);
            list.add(userInfo);
        }
        long start = System.currentTimeMillis();
        if ("mybatis-plus".equals(type)) {
            this.saveBatch(list);
        } else {
            //分批插入,每次插入1000条
            List<List<UserInfo>> listList = ListUtil.partition(list, 1000);
            listList.forEach(e -> userInfoMapper.insertBatch(e));
        }
        long end = System.currentTimeMillis();
        System.out.println(type + "批量插入(" + total + "条)数据所用时间: " + (end - start) / 1000.00 + "s");
    }

测试结果如下:

1.1 数据库url未加rewriteBatchedStatements=true

1.1 数据库url加rewriteBatchedStatements=true

标签:批量,性能,插入,plus,userInfo,mybatis,1000
From: https://www.cnblogs.com/zhaodalei/p/16788822.html

相关文章

  • mysq根据id批量进行修改
     UPDATEAasaINNERJOINBasbONb.aid=a.idANDa.is_deleted=0 SETa.字段1=b.value1,   a.字段2=b.value2,   a.字段3=b.value3 WHEREa.id=b.aid# ......
  • 使用 ADManager Plus管理Microsoft Office 365
    Microsoft365浪潮席卷了全球各种规模和职能的组织。它使进入云变得容易且具有成本效益,而无需放弃熟悉的Microsoft服务器和客户端应用程序。其成功和在全球范围内广泛采......
  • python批量编译pyd并保持原有的目录结构
    参考https://blog.csdn.net/joyopirate/article/details/118609151使用时,将文件放在项目的最外层的目录即可#-*-coding:UTF-8-*-__author__='Arvin'__modifier_......
  • 根据excel数据和pdf模板批量生成pdf
    案例批量生成合同1、准备存储数据的excel和对应的pdf      2、利用 AdobeAcrobatDC  制作pdf模板具体流程如下1>下载AdobeAcrobatDC并安......
  • spring中@Param和mybatis中@Param使用区别(暂时还没接触)
    1、spring中@Param(org.springframework.data.repository.query.Param)intselectRoleCount(@Param("businessId")IntegerbusinessId,@Param("memberId")Long2、mybatis......
  • ElementPlus的MessageBox自动关闭
    <template><el-rowclass="mb-4"><el-button@click="open"type="primary"show-confirm-button="false">Click</el-button></el-row></template><scripts......
  • Mybatis---动态查询(choose,when,otherwise)
    choose(when,otherwise)标签有时候我们并不想应用所有的条件,而只是想从多个选项中选择一个。而使用if标签时,只要test中的表达式为true,就会执行if标签中的条件。MyBat......
  • CAD批量打印MSTEEL
    目录一、安装二、批量打印到文件(通用型)2.1打印流程2.1.1选择2.1.2界面三、批量打印到文件(图框型)3.1图框白名单设置3.2打印流程四、校对图框信息一、安装软件网址:MS......
  • Mybatis传递多个参数的几种方式
    1、顺序传参法publicUserselectUser(Stringname,intdeptId);<selectid="selectUser"resultMap="UserResultMap">select*fromuserwhereuser_name......
  • MyBatis中三种分页查询方式
    文章目录通过limit分页查询通过Rowbounds通过分页插件pagehelper通过limit分页查询mapper接口1List<User>getUserByLimit(Map<String,Integer>map);mapper.xm......