MYSIAM表 并发插入

来源:互联网 发布:汽车设计软件发展趋势 编辑:程序博客网 时间:2024/06/03 20:12

上篇文章提到MyISAM表的读和写操作是串行的,但这只是总体而言的。在一定条件下,MyISAM表也支持查询和插入操作的并发进行。

MyISAM存储引擎的系统变量concurrent_insert,专门用以控制其并发插入的行为。

concurrent_insert(官方文档对这个参数的说明)

If AUTO (the default), MySQL permits INSERT and SELECT statements to run concurrently for MyISAM tables that have no free blocks in the middle of the data file. If you startmysqld with--skip-new, this variable is set toNEVER.

This variable can take the values shown in the following table. The variable can be assigned using either the name values or corresponding integer values.

ValueDescriptionNEVER (or 0)Disables concurrent insertsAUTO (or 1)(Default) Enables concurrent insert for MyISAM tables that do not have holesALWAYS (or 2)Enables concurrent inserts for all MyISAM tables, even those that have holes. For a table with a hole, new rows are inserted at the end of the table if it is in use by another thread. Otherwise, MySQL acquires anormal write lock and inserts the row into the hole.

0:不允许并发插入

1:(默认值)如果MYISAM表中没有空洞(即表中间没有被删除的行),MYSIAM允许在一个进程读表的同时,另一个进程从表尾插入记录。

2:无论MYSIAM表有没有空洞,都允许在表尾并发的插入记录。如果是得到了普通的写锁(即只有自己一个会话在使用表),那就可以将数据插入到空洞中。


当会话session1获得表的READ LOCAL锁,该线程可以对表进行查询操作,但不能对表进行操作;其他的会话(session2)虽然不能对表进行删除和

更新操作,但却可以对表进行并发插入操作,这里假设该表中间不存在空洞。


0 0
原创粉丝点击