【位图索引】在位图索引列上进行更新操作的锁代价研究

   位图索引的特点是不支持行级锁定,锁代价很高,请参见文章《【实验】【Bitmap Index】位图索引的锁代价研究》(http://space.itpub.net/519536/viewspace-611296)。

  提问:若将具有位图索引列的一类值更新为其他已有值信息,是否会锁定两类值的全部记录?

  回答:会!

  这也进一步体现了位图索引导致的极高锁代价!

  我们用实验来说明一下这个问题,这样会更加的直观。

1.创建测试表T
sec@ora10g> create table t (x varchar2(10));

Table created.

2.初始化4条数据
sec@ora10g> insert into t values ('Secooler');

1 row created.

sec@ora10g> insert into t values ('Secooler');

1 row created.

sec@ora10g> insert into t values ('HOU');

1 row created.

sec@ora10g> insert into t values ('HOU');

1 row created.

sec@ora10g> commit;

Commit complete.

sec@ora10g> select * from t;

X
----------
Secooler
Secooler
HOU
HOU

3.在T表的X列上创建位图索引
sec@ora10g> create bitmap index t_bitmap_idx on t(x);

Index created.

4.设计更新操作场景
1)第一个session中尝试将已有的“HOU”记录更新为已有的记录“Secooler”
sec@ora10g> update t set x = 'Secooler' where x = 'HOU';

2 rows updated.

2)第二个session中尝试更新“Secooler”记录行
sec@ora10g> update t set x = 'Good luck.' where x='Secooler';

  特别注意,此时出现了锁等待现象!此条语句无法完成。

  因此也证实了若将具有位图索引列的一类值更新为其他已有值信息,的确会锁定两类值的全部记录这个结论。

5.小结
  通过这个实验大家应该更加深入体会到位图索引的锁代价是非常大的。在考虑使用位图索引时需要重点考虑这些因素。

Good luck.

secooler
11.05.03

-- The End --

请使用浏览器的分享功能分享到微信等