位图索引的特点是不支持行级锁定,锁代价很高,请参见文章《【实验】【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 --
提问:若将具有位图索引列的一类值更新为其他已有值信息,是否会锁定两类值的全部记录?
回答:会!
这也进一步体现了位图索引导致的极高锁代价!
我们用实验来说明一下这个问题,这样会更加的直观。
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 --
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-694385/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/519536/viewspace-694385/