读书人

B-Tree索引与Bit地图索引的锁代价的比

发布时间: 2012-11-20 09:55:43 作者: rapoo

B-Tree索引与Bitmap索引的锁代价的比较

环境:

①--建表SQL> create table t_bitmap (id number(10),name varchar2(10),sex varchar2(1));表已创建。SQL> create bitmap index t_bitmap_idx on t_bitmap(sex);索引已创建。SQL> create table t_btree (id number(10),name varchar2(10),sex varchar2(1));表已创建。SQL> create index t_btree_idx on t_btree(sex);索引已创建。SQL> insert into t_btree values (1,'think','M');已创建 1 行。SQL> insert into t_btree values (2,'qinqin','F');已创建 1 行。SQL> insert into t_bitmap values(1,'think','M');已创建 1 行。SQL> insert into t_bitmap values(2,'qinqin','F');已创建 1 行。SQL> commit;提交完成。SQL> select * from t_btree;        ID NAME       S---------- ---------- -         1 think      M         2 qinqin     FSQL> select * from t_bitmap;        ID NAME       S---------- ---------- -         1 think      M         2 qinqin     F②--对Btree index进行DML***********session_A***************SQL> insert into t_btree values (3,'hangzhen','M');已创建 1 行。***********session_B***************SQL> insert into t_btree values (4,'yuechuang','M');已创建 1 行。SQL> update t_btree set sex='M' where id=2;已更新 1 行。SQL> delete from t_btree;已删除3行。③--对Bitmap index进行DML***********session_A****************SQL> insert into t_bitmap values (3,'hangzhen','M');已创建 1 行。***********session_B******************㈠ insert动作SQL> insert into t_bitmap values (4,'yuechuang','M');--出现锁等待当插入数据未涉及位图索引列“sex”字段时,是可以完成的SQL> insert into t_bitmap (id,name) values (4,'yuechuang');已创建 1 行。㈡ update动作当更新位图索引列“sex”字段值为“M”时,是无法完成的SQL> select * from t_bitmap;        ID NAME       S---------- ---------- -         1 think      M         2 qinqin     F         4 yuechuangSQL> update t_bitmap set sex='M' where id=1;已更新 1 行。此时成功,是因为第1行数据的sex值本身就是“M”。SQL> update t_bitmap set sex='M' where id=4;--锁等待。SQL> update t_bitmap set sex='M' where id=2;--锁等待特别注意一下,如果更新的列不是位图索引对应的列,将不会受位图段级索引锁的限制SQL> update t_bitmap set name='Water' where  id=1;已更新 1 行。㈢ delete 动作SQL> select * from t_bitmap;        ID NAME       S---------- ---------- -         3 hangzhen   M         4 yuechuang  F         5 ss         MSQL> delete from t_bitmap where id=3;--锁等待SQL> delete from t_bitmap where id=4;已删除 1 行。SQL> delete from t_bitmap where id=5;--锁等待

--小结


对于B-Tree索引来说,插入动作不影响其他会话的DML操作
对于Bitmap索引来说,由于是索引段级锁,会导致与操作列值相关的内容被锁定(文中提到的“M”信息)。


1楼syzcch前天 17:09
总结的不错啊

读书人网 >其他数据库

热点推荐