我刚才做了一个实验,早上的时候结果是可以重现,但现在做却结果不一样,实验过程如下:步骤1、在Session 1上
mysql> lock table SCMyISAM read; 这时Session 1、Session 2、Session 3都可以对这张表进行select操作
步骤2、在Session 2上
update SCMyISAM set workerid=9999 where memberid=7282918;
此时该语句等待,因为Session 1加的读锁没释放步骤3、在Session 3上
mysql> select memberid,workerid from SCMyISAM limit 5;
(我的理解)此时该语句也在等待,因为mysql的写锁的优先级比读锁高,所以该语句要等Session 2获得写锁并释放后才能进行读操作步骤4、在Session 1上
mysql> unlock tables;此时Session 2和Session 3都可以执行了。
以上是早上的实验结果,刚才我再实验了一下,在步骤3时,那条语句不再是等待,而是直接给出了结果,这是什么原因呢?

解决方案 »

  1.   

    The MyISAM storage engine supports concurrent inserts to reduce contention between readers and writers for a given table: If a MyISAM table has no free blocks in the middle of the data file, rows are always inserted at the end of the data file. In this case, you can freely mix concurrent INSERT and SELECT statements for a MyISAM table without locks. That is, you can insert rows into a MyISAM table at the same time other clients are reading from it.