楼主: biti_rainy

[精华] bitmap 的一点探究

[复制链接]
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
11#
发表于 2004-7-6 10:46 | 只看该作者
考虑完单条记录的情况,下面来看一下多条记录的情况

在上面的例子中
SQL> select rowid, id, age from test_bitmap;

ROWID ID AGE
------------------ ---------- ----------
AAAH2WAALAAAAUWAAA 1 1
AAAH2WAALAAAAUWAAB 2 1
AAAH2WAALAAAAUWAAC 3 2
AAAH2WAALAAAAUWAAD 4 1
AAAH2WAALAAAAUWAAE 5 1
AAAH2WAALAAAAUWAAF 6 1
AAAH2WAALAAAAUWAAG 7 1
AAAH2WAALAAAAUWAAH 8 1
AAAH2WAALAAAAUWAAI 9 1
AAAH2WAALAAAAUWAAJ 10 3

row#2[16136] flag: -----, lock: 2
col 0; len 2; (2): c1 02
col 1; len 6; (6): 02 c0 05 16 00 00
col 2; len 6; (6): 02 c0 05 16 00 07
col 3; len 2; (2): c8 fb

把fb变为二进制
11111011
与上面的rowid结合可以看出,这种情况下,有1的位置表示这条记录符合当前索引的键值。
从高位到低位分别表示了这个索引段中的第8表记录到第1条记录

btw:忘了说明一点,我这里提到的索引段都是biti在文章开始时说明的索引分段存储的“段”,而不是我们常说的INDEX SEGMENT

使用道具 举报

回复
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
12#
发表于 2004-7-6 11:07 | 只看该作者
SQL> insert into test_bitmap select 11+rownum, 'a', 4 from dba_tables where rownum < 81;

已创建80行。

SQL> alter system dump datafile 11 block 1352;

系统已更改。


Leaf block dump
===============
header address 141636196=0x8713264
kdxcolev 0
KDXCOLEV Flags = - - -
kdxcolok 0
kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y
kdxconco 4
kdxcosdc 0
kdxconro 8
kdxcofbo 52=0x34
kdxcofeo 16061=0x3ebd
kdxcoavs 16009
kdxlespl 0
kdxlende 3
kdxlenxt 0=0x0
kdxleprv 0=0x0
kdxledsz 0
kdxlebksz 16228
row#0[16201] flag: ---D-, lock: 2
col 0; len 2; (2):  c1 02
col 1; len 6; (6):  02 c0 05 16 00 00
col 2; len 6; (6):  02 c0 05 16 00 07
col 3; len 1; (1):  00
row#1[16179] flag: ---D-, lock: 2
col 0; len 2; (2):  c1 02
col 1; len 6; (6):  02 c0 05 16 00 00
col 2; len 6; (6):  02 c0 05 16 00 07
col 3; len 2; (2):  c8 03
row#2[16136] flag: -----, lock: 2
col 0; len 2; (2):  c1 02
col 1; len 6; (6):  02 c0 05 16 00 00
col 2; len 6; (6):  02 c0 05 16 00 07
col 3; len 2; (2):  c8 fb
row#3[16115] flag: -----, lock: 2
col 0; len 2; (2):  c1 02
col 1; len 6; (6):  02 c0 05 16 00 08
col 2; len 6; (6):  02 c0 05 16 00 0f
col 3; len 1; (1):  00
row#4[16158] flag: -----, lock: 2
col 0; len 2; (2):  c1 03
col 1; len 6; (6):  02 c0 05 16 00 00
col 2; len 6; (6):  02 c0 05 16 00 07
col 3; len 1; (1):  02
row#5[16094] flag: -----, lock: 2
col 0; len 2; (2):  c1 04
col 1; len 6; (6):  02 c0 05 16 00 08
col 2; len 6; (6):  02 c0 05 16 00 0f
col 3; len 1; (1):  01
row#6[16061] flag: -----, lock: 2
col 0; len 2; (2):  c1 05
col 1; len 6; (6):  02 c0 05 16 00 08
col 2; len 6; (6):  02 c0 05 16 00 5f
col 3; len 13; (13):  cf fc ff ff ff ff ff ff ff ca ff ff 03
row#7[16222] flag: ---D-, lock: 2
col 0; NULL
col 1; NULL
col 2; NULL
col 3; NULL
----- end of leaf block dump -----
End dump data blocks tsn: 11 file#: 11 minblk 1352 maxblk 1352

我们继续看这个例子
由于范围08-0f之间还有空闲空间,索引范围分配还是从08开始,一个80条记录,由于前8个位置中有其他记录,索引一个分配了5×16+15-8+1=88个rowid的范围。

fc变为二进制是11111100,最低二位已经被占有,索引这个索引段存储了6条记录
而最后一个索引段存储了两条记录 03  -> 00000011,加在一起正好是80条记录。

中间的ca和开头的cf,不是索引的bitmap,而是类似数据头之类的东西,具体数值代表什么我还不清楚,不过似乎每64位就会出现一个数据头。

根据上面的几个例子,似乎索引段中的bitmap编码如实反应了记录在索引段中的位置,并不需要颠倒bit的位置。

使用道具 举报

回复
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
13#
发表于 2004-7-6 11:22 | 只看该作者
以上是最近研究的一点心得,欢迎大家讨论。

结合最后一个例子,发现我的那个公式还是有问题的。
应该分成两部分来考虑
如果部分空闲的那个索引段中保存的键值和当前插入数据键值的相同,oracle会修改以前那个索引段。然后重新分配新的索引范围。
这是新分配的空间和我公式给出的结果一致。

如果部分空闲的那个索引段中保存的键值和当前插入数据键值的不同,则参考上面的例子,oracle会从空闲的那个范围开始分配。这是分配的范围的大小就比公式的结果多出8。

当然上面都是考虑比较简单的情况,当插入的批操作中包含多个值时,每个值范围的大小不但和批操作的数据量有关,也和当前值在批操作中物理分布有关。

使用道具 举报

回复
论坛徽章:
86
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20咸鸭蛋
日期:2012-05-08 10:27:19版主8段
日期:2012-05-15 15:24:112013年新春福章
日期:2013-02-25 14:51:24
14#
 楼主| 发表于 2004-7-6 13:19 | 只看该作者
呵呵,没有你们的研究,哪里能获得更深入的了解  

独角戏是唱不下去的

如果是先有了大量的数据,来创建bitmap,记得这个 分"段" 的标准应该是和 extents 有关系的

使用道具 举报

回复
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
15#
发表于 2004-7-6 14:06 | 只看该作者
SQL> truncate table test_bitmap;

表已截掉。

SQL> desc test_bitmap
名称                                      是否为空? 类型
----------------------------------------- -------- ----------------------------
ID                                                 NUMBER
NAME                                               VARCHAR2(20)
AGE                                                NUMBER(3)

SQL> alter table test_bitmap modify (name varchar2(4000));

表已更改。

SQL> insert into test_bitmap select rownum, rpad('1', 4000, '1'), 1 from dba_tables where rownum < 1;

已创建1000行。

SQL> commit;

提交完成。

SQL> alter system dump datafile 11 block 1352;

系统已更改。

SQL> col segment_name format a30
SQL> select segment_name, extent_id from  user_extents where segment_name = 'TEST_BITMAP';

SEGMENT_NAME                    EXTENT_ID
------------------------------ ----------
TEST_BITMAP                             0
TEST_BITMAP                             1
TEST_BITMAP                             2
TEST_BITMAP                             3
TEST_BITMAP                             4
TEST_BITMAP                             5

已选择6行。

Leaf block dump
===============
header address 141636196=0x8713264
kdxcolev 0
KDXCOLEV Flags = - - -
kdxcolok 0
kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y
kdxconco 4
kdxcosdc 0
kdxconro 2
kdxcofbo 40=0x28
kdxcofeo 14868=0x3a14
kdxcoavs 14828
kdxlespl 0
kdxlende 1
kdxlenxt 0=0x0
kdxleprv 0=0x0
kdxledsz 0
kdxlebksz 16228
row#0[14868] flag: -----, lock: 2
col 0; len 2; (2):  c1 02
col 1; len 6; (6):  02 c0 05 08 00 00
col 2; len 6; (6):  02 c0 06 c4 00 07
col 3; len 1333; (1333):
c8 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 ed 5f 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 ed 02 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 ed 02 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 ed
02 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8
b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3
01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01
07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07 f8 b3 01 07
f8 9b 07 07 f8 e1 05 07 f8 e1 05 07 f8 a7 04 07 f8 b3 01 07 f8 a7 04 07 f8
b3 01 07 f8 a7 04 07 f8 b3 01 07 f8 a7 04 07 f8 b3 01 07 f8 a7 04 07 c0 a1
01 f8 a7 04 07 f8 e1 05 07 f8 e1 05 07 f8 e1 05 07 f8 e1 05 07 f8 e1 05 07
f8 e1 05 07 f8 e1 05 07
row#1[16222] flag: ---D-, lock: 2
col 0; NULL
col 1; NULL
col 2; NULL
col 3; NULL
----- end of leaf block dump -----
End dump data blocks tsn: 11 file#: 11 minblk 1352 maxblk 1352


这里虽然是五个extents,但是bitmap索引仍然是一个索引段

另外,我仔细看了一下上面的bitmap编码,发现每个block中只能放3条记录,也就是说,上面的07才是真正的编码。而 f8 b3 01应该是oracle用来表示block结束的。不过具体含义是什么,还是不得而知

使用道具 举报

回复
论坛徽章:
86
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20咸鸭蛋
日期:2012-05-08 10:27:19版主8段
日期:2012-05-15 15:24:112013年新春福章
日期:2013-02-25 14:51:24
16#
 楼主| 发表于 2004-7-6 14:10 | 只看该作者
你这5个extent在 block序号上是相临连续的吧 ?

使用道具 举报

回复
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
17#
发表于 2004-7-6 14:16 | 只看该作者
是的,看来还是物理上的存储位置决定的。

使用道具 举报

回复
论坛徽章:
30
ITPUB元老
日期:2005-02-28 12:57:00ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41管理团队成员
日期:2011-05-07 01:45:082010数据库技术大会纪念徽章
日期:2010-05-13 09:34:23数据库板块每日发贴之星
日期:2006-06-21 01:01:30数据库板块每日发贴之星
日期:2006-06-12 01:01:37会员2006贡献徽章
日期:2006-04-17 13:46:34数据库板块每日发贴之星
日期:2005-12-03 01:01:33授权会员
日期:2005-10-30 17:05:33ITPUB社区OCM联盟徽章
日期:2014-04-01 13:07:37
18#
发表于 2004-8-2 17:37 | 只看该作者

Oracle关于bitmap 索引的文档

Contents
1. How do we store a bitmap index?
2. Example
3. Bitmapped index blockdump
4. Miscellaneous

1. How do we store a bitmap index?

   Essentially this is a three-step operation:

     I. A bitmap is created for every distinct key column value.
    II. The bitmaps are then compressed.
   III. The compressed bitmaps are stored in a normal B-TREE index
        structure along with the keyvalue, and a ROWID range. The
        ROWID range is the range of ROWIDs in the base table to which
        this bitmap applies.

2. Example

   This is best illustrated with an example. The standard EMP table
   has been modified to include a politically incorrect GENDER column.
   GENDER is a CHAR(1) datatype and takes values 'M' or 'F'.

     CREATE TABLE EMP
       (EMPNO NUMBER(4) NOT NULL,
        ENAME VARCHAR2(10),
        GENDER CHAR(1),
        JOB VARCHAR2(9),
        MGR NUMBER(4),
        HIREDATE DATE,
        SAL NUMBER(7,2),
        COMM NUMBER(7,2),
        DEPTNO NUMBER(2));

   The table has 14 rows inserted into it:

     INSERT INTO EMP VALUES
        (7369,'SMITH','M','CLERK',7902,'17-DEC-80',800,NULL,20);
     INSERT INTO EMP VALUES
        (7499,'ALLEN','M','SALESMAN',7698,'20-FEB-81',1600,300,30);
     INSERT INTO EMP VALUES
        (7521,'WARD','M','SALESMAN',7698,'22-FEB-81',1250,500,30);
     INSERT INTO EMP VALUES
        (7566,'JONES','F','MANAGER',7839,'2-APR-81',2975,NULL,20);
     INSERT INTO EMP VALUES
        (7654,'MARTIN','F','SALESMAN',7698,'28-SEP-81',1250,1400,30);
     INSERT INTO EMP VALUES
        (7698,'BLAKE','M','MANAGER',7839,'1-MAY-81',2850,NULL,30);
     INSERT INTO EMP VALUES
        (7782,'CLARK','M','MANAGER',7839,'9-JUN-81',2450,NULL,10);
     INSERT INTO EMP VALUES
        (7788,'SCOTT','F','ANALYST',7566,'09-DEC-82',3000,NULL,20);
     INSERT INTO EMP VALUES
        (7839,'KING','F','PRESIDENT',NULL,'17-NOV-81',5000,NULL,10);
     INSERT INTO EMP VALUES
        (7844,'TURNER','F','SALESMAN',7698,'8-SEP-81',1500,0,30);
     INSERT INTO EMP VALUES
        (7876,'ADAMS','M','CLERK',7788,'12-JAN-83',1100,NULL,20);
     INSERT INTO EMP VALUES
        (7900,'JAMES','F','CLERK',7698,'3-DEC-81',950,NULL,30);
     INSERT INTO EMP VALUES
        (7902,'FORD','M','ANALYST',7566,'3-DEC-81',3000,NULL,20);
     INSERT INTO EMP VALUES
        (7934,'MILLER','F','CLERK',7782,'23-JAN-82',1300,NULL,10);

   A bitmap index, EMP$GENDER$BMIDX is created on EMP (GENDER):

     CREATE BITMAP INDEX EMP$GENDER$BMIDX ON EMP (GENDER);

   This is how the bitmap index is stored internally:

     I. A bitmap is created for every distinct key column value. In
        this case, there are 2 distinct values, 'M' and 'F'. If the
        rows are stored in the order above, then the 2 bitmaps will
        look like this:

          'M': 11100110001010
          'F': 00011001110101

        (Note, you XOR the bitmaps for all the distinct key values,
         you will end up with a bitmap of '1's).

    II. The bitmaps are then compressed (see (4))

   III. The compressed bitmaps are stored in a normal B-TREE index
        structure along with the keyvalue and a ROWID range. The
        ROWID range is the range of ROWIDs in the base table to which
        this bitmap applies.


3. Bitmapped index blockdump

   In the above example, 2 B-TREE index entries are created, one
   for each of the unique index keys. A dump of the index block
   shows:

     << lines cut here >>
     row#0[1866] flag: ----, lock: 0
     col 0; len 1; (1):  46
     col 1; len 6; (6):  01 00 00 0d 00 00
     col 2; len 6; (6):  01 00 00 0d 00 0f
     col 3; len 3; (3):  c9 98 2b
     row#1[1844] flag: ----, lock: 0
     col 0; len 1; (1):  4d
     col 1; len 6; (6):  01 00 00 0d 00 00
     col 2; len 6; (6):  01 00 00 0d 00 0f
     col 3; len 3; (3):  c9 67 14
     ----- end of leaf block dump -----

   Notes:
     col 0: key value (46 is ascii 'F', 4d is ascii 'M')
     col 1: ROWID range lower bound
     col 2: ROWID range upper bound
     col 3: compressed bitmap for this key

   In this example, the bitmaps for both keys point to rows 0 through
   15 in DBA 0x0100000d (the datablock in EMP containing the rows).

   
4. Miscellaneous

   4.1. There can be more than one index entry per distinct key

     The above example is a very simple case. Because of the small
     number of rows, the bitmap index contains one B-TREE entry per
     key value. If the table was large, and/or if the key values in
     the table were clustered poorly, there would be multiple index
     entries per distinct key value.

   4.2. Analyzing bitmap indexes

     Be wary about statistics produced by analyzing bitmap indexes.
     For example, we recently had a call from someone who had
     analyzed a large table, and USER_INDEXES.NUM_ROWS reported
     substantially fewer rows in the bitmap index than in the base
     table. This is expected - analyze would have simply calculated
     the number of B-TREE entries.
     
   4.3. Bitmap indexes, locking and concurrency

     Bitmapped indexes are not suitable for key columns that are the
     subject of DML. The reason for this is that if the key is
     modified, the index associated index entry (the bitmap) must
     also be updated, and therefore locked for the duration of the
     transaction. Whilst the index entry is locked, any other updates
     on the key column (for rows 'covered' by this bitmap) are
     prohibited.

     The extent of the problem depends entirely upon how many index
     entries exist per distinct index key. If all rows for this key
     are 'covered' by one bitmap (and therefore one index entry)
     then a transaction that updates this key value in the base table
     will block all other updates of this value until the transaction
     commits or rolls back.

   4.4. Compression

     To Be Written. Please 'Add Remark' if have information to be included
     in this section.

使用道具 举报

回复
论坛徽章:
226
BLOG每日发帖之星
日期:2010-02-11 01:01:06紫蛋头
日期:2013-01-12 23:45:222013年新春福章
日期:2013-02-25 14:51:24问答徽章
日期:2013-10-17 18:06:40优秀写手
日期:2013-12-18 09:29:10马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:14
19#
发表于 2004-8-2 18:02 | 只看该作者
呵呵,这篇文章从哪里找到的。很不错。
概念描述的十分清晰,可惜深度不够。

使用道具 举报

回复
论坛徽章:
30
ITPUB元老
日期:2005-02-28 12:57:00ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41管理团队成员
日期:2011-05-07 01:45:082010数据库技术大会纪念徽章
日期:2010-05-13 09:34:23数据库板块每日发贴之星
日期:2006-06-21 01:01:30数据库板块每日发贴之星
日期:2006-06-12 01:01:37会员2006贡献徽章
日期:2006-04-17 13:46:34数据库板块每日发贴之星
日期:2005-12-03 01:01:33授权会员
日期:2005-10-30 17:05:33ITPUB社区OCM联盟徽章
日期:2014-04-01 13:07:37
20#
发表于 2004-8-2 18:21 | 只看该作者
嗯,好象是WebIV上的吧,我都记不清是从哪儿倒腾来的了,还有X$表的定义那些的,净是些mht文档。反正一个个都标着Confidential - Internal Use Only,其实资料多了也不是什么好事,能静下心看懂一本书比东一榔头西一棒子要好多了。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表