Will insert be locked? If it's locked, what's the point?
Update and delete in innodb will implicitly add exclusive lock,
update table set... where id in (1,2,3,4); What is the exclusive lock? Add these four records directly, or lock, modify and commit in sequence according to the ID;
Will delete and update implicitly add write locks?
Will select implicitly add a read lock?
If it is added in two situations, both are table lock levels, then the concurrency is particularly bad, right?
Choice of two engines
MyISAM: If you execute a large number of SELECTs, MyISAM is a better choice. Why is this? I actually tested 3.6 million pieces of data, all of which used index selection. Innodb is much more efficient.
InnoDB: If your data performs a large number of INSERT or UPDATE, you should use an InnoDB table. Is this because of the myisam table lock?
谢邀。
InnoDB
InnoDB对
INSERT
可能只锁表头吧,总之不会锁全表的;UPDATE
(如果没有FOR UPDATE
或LOCK IN SHARE MODE
)和DELETE
在执行时会加写锁,有时就是锁全表,所以会影响并发性能,但这只是一瞬间的事,所以并发不高的情况下往往看不出来;一次
UPDATE
多行,肯定是多行一起锁,提交后一起释放的,因为MySQL要保证这条语句的原子性,当一条有主键冲突时,其他的也都不能提交了。MySQL
UPDATE
和DELETE
都会加写锁,而且锁全表;SELECT
会加读锁,所以多个SELECT
可以并发,但不能和UPDATE
、DELETE
并发;INSERT
的加锁有点特殊,锁的强度可能介于读锁和写锁之间,与SELECT
、INSERT
可以并发。最后,MyISAM就
SELECT
而言性能不会比InnoDB好很多,这还取决于行的存储方式,比如MyISAM的FIXED
可能会比DYNAMIC
快一些。另外,你的这个例子肯定会对InnoDB更有利些:如果改成一个非主键的索引,那么InnoDB未必会那么快;如果只SELECT id这一列,那么MyISAM未必这么慢。其中的道理可以搜一下聚集索引。