mysql 事物 分批次提交_事务分批次多条提交与每条记录提交性能比对

本文通过创建测试表并执行分批次与逐条提交事务的实验,对比了两种方式在插入大量记录时的性能差异。实验结果显示,分批次提交事务的时间为5.760秒,而逐条记录提交则耗时25.265秒,表明分批次提交具有显著的性能优势。
摘要由CSDN通过智能技术生成

测试目的:验证总记录数下,每次提交多条记录,与一条记录提交一次,性能的差异。

测试步骤:

1、创建测试表:

create table tcommittable(

t_id int(10),

t_name varchar(20),

PRIMARY KEY(t_id)

);

2、分批次提交事务过程:

drop procedure if exists tcommit;

delimiter $$

create procedure tcommit()

begin

declare i int default 1;

select now();

while i < 10000 do

insert into tcommittable(t_id, t_name)

values (i, 'a'||i)

on duplicate key update t_name = 'b'||i;

if i % 3000 = 0 then

commit;

end if;

set i = i + 1;

end while;

commit;

select now();

end$$

delimiter ;

call tcommit;

3、一条条提交过程:

drop procedure if exists tcommit;

delimiter $$

create procedure tcommit()

begin

declare i int default 1;

select now();

while i < 10000 do

insert into tcommittable(t_id, t_name)

values (i, 'a'||i)

on duplicate key update t_name = 'b'||i;

commit;

set i = i + 1;

end while;

select now();

end$$

delimiter ;

call tcommit;

测试结果:

分批次:时间: 5.760s

每条记录提交:时间: 25.265s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值