开发者

MySQL Cost: InnoDB on Cascade or MyISAM separate deletes

开发者 https://www.devze.com 2023-03-18 08:27 出处:网络
I\'m curious as to which would be more cost efficient in terms of resourc开发者_StackOverflowes used by the server: On Cascade Delete that traverses multiple tables or multiple delete statements with

I'm curious as to which would be more cost efficient in terms of resourc开发者_StackOverflowes used by the server: On Cascade Delete that traverses multiple tables or multiple delete statements with the MyISAM engine?


On Cascade Delete have multiple advantages:

  • it can use transaction, so if one delete fails, all will fail and data will remain consistent
  • InnoDB uses row-level locks. To delete a record from MyISAM, entire table have to be locked. If there are a lot of concurrent queries, InnoDB will be faster.
  • As @Itay Moav said, with on cascade delete you will perform only one query, while with multiple deletes - multiple queries.


The second option will also require the system to talk back and froth the mysql client and the mysql server, while the first option will just do it in one call. Also easier to fix with InnoDB if you put it all in a transaction.

0

精彩评论

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