mysql batch 过长_MySQL-Mysql 使用Batch能提高写效率吗

1.对于支持事务的表可以采用事务处理。加快批量处理。

原因:

a.对于支持事务的,其实单条语句也是一个事务,所以redo,undo 及其他日志也是必不可少的。并且每个语句都作为事务,记录的日志反而会多些。

b.另外就是批量写入的原因了。

2.对于非事务的表。采用表锁方式。

LOCK TABLES a WRITE;

INSERT INTO a VALUES (1,23),(2,34),(4,33);

INSERT INTO a VALUES (8,26),(6,29);

...

UNLOCK TABLES;

表锁方式之所以快,是因为索引buffer 只需要被刷新到磁盘一次,而其他则是每个insert 都要写入。

This benefits performance because the index buffer is flushed to disk only once, after all INSERT statements have completed. Normally, there would be as many index buffer flushes as there are INSERT statements. Explicit locking statements are not needed if you can insert all rows with a single INSERT.

To obtain faster insertions for transactional tables, you should use START TRANSACTION and COMMIT instead of LOCK TABLES.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值