开发者

InnoDB optimization - "use transactions when doing updates" - why?

I was reading this post on the MySQL performance blog.

Under application tuning it says:

First make sure you’re using transactions when doing updates

I am currently only using transactions in places where there are multiple inserts or updates at the same time. i.e. more than one table.

Should I therefore alter every UPDATE to change it into a transaction?

What is the difference between:

prepare sql
bind params
commit

and:

begin transaction
prepare sql
bind params
execute statement
commit transaction

in terms of what happens at the database le开发者_JAVA百科vel, that makes one faster than the other?


InnoDB runs in autocommit mode by default. What it means is that every query runs in it's own transaction and gets commited at once. In InnoDB this mean writing data into two places on disk (don't ask me for details - I'm writing from memory what I've read at MySQL Performance Blog once ;) ).

Now, if you do one update/insert/delete at a time, there's not much performance to gain. However, if you do several consecutive update/inserts/deletes, you can save some hard disk time by bundling them into transaction, and then commiting all at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜