唯一索引和非唯一索引在结构上有一些区别,下面就来分析这些区别。
结构区别
root block和branch block结构基本一样,引用之前dump的非唯一索引分析。
非唯一索引的branch block
- Branch block dump
- =================
- header address 140186507995716=0x7f7fb702ea44
- kdxcolev 1
- KDXCOLEV Flags = - - -
- kdxcolok 1
- kdxcoopc 0x85: opcode=5: iot flags=--- is converted=Y
- kdxconco 2
- kdxcosdc 1
- kdxconro 619
- kdxcofbo 1266=0x4f2
- kdxcofeo 2550=0x9f6
- kdxcoavs 1284
- kdxbrlmc 4229529=0x408999
- kdxbrsno 616
- kdxbrbksz 8056
- kdxbr2urrc 0
- row#0[4863] dba: 4230420=0x408d14
- col 0; len 3; (3): 34 34 30
- col 1; TERM
- row#1[4872] dba: 4230034=0x408b92
- col 0; len 3; (3): 34 34 31
- col 1; TERM
- row#2[4881] dba: 4229537=0x4089a1
- col 0; len 3; (3): 34 34 32
- col 1; TERM
- row#3[4890] dba: 4230422=0x408d16
- col 0; len 3; (3): 34 34 33
- col 1; TERM
- ...
- row#617[2559] dba: 4230888=0x408ee8
- col 0; len 3; (3): 39 39 37
- col 1; TERM
- row#618[8047] dba: 4229865=0x408ae9
- col 0; len 3; (3): 39 39 38
- col 1; TERM
-
唯一索引的branch block
- Branch block dump
- =================
- header address 140045722856004=0x7f5eef902a44
- kdxcolev 1
- KDXCOLEV Flags = - - -
- kdxcolok 0
- kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y
- kdxconco 1
- kdxcosdc 0
- kdxconro 33
- kdxcofbo 94=0x5e
- kdxcofeo 7828=0x1e94
- kdxcoavs 7734
- kdxbrlmc 4229050=0x4087ba
- kdxbrsno 0
- kdxbrbksz 8056
- kdxbr2urrc 0
- row#0[8049] dba: 4229051=0x4087bb
- col 0; len 2; (2): 31 31
- row#1[8042] dba: 4229052=0x4087bc
- col 0; len 2; (2): 31 34
- row#2[8035] dba: 4229053=0x4087bd
- col 0; len 2; (2): 31 37
- row#3[8029] dba: 4229054=0x4087be
- col 0; len 1; (1): 32
- ...
- col 0; len 2; (2): 39 33
- row#31[7835] dba: 4229106=0x4087f2
- col 0; len 2; (2): 39 36
- row#32[7828] dba: 4229107=0x4087f3
- col 0; len 2; (2): 39 39
- 1.唯一索引和非唯一索引的root block和branch block结构大体基本一致,具体的结构分析见上一节对root block和branch block的分析。
- 2.非唯一索引的root block和branch block的kdxconco总比唯一索引的root block和branch block的kdxconco少1,因为唯一索引的root block和branch block不需要存储rowid或rowid前缀,这里对应的是每行的col 1。
非唯一索引的leaf block
- Leaf block dump
- ===============
- header address 140186507995740=0x7f7fb702ea5c
- kdxcolev 0
- KDXCOLEV Flags = - - -
- kdxcolok 1
- kdxcoopc 0x87: opcode=7: iot flags=--- is converted=Y
- kdxconco 2
- kdxcosdc 1
- kdxconro 2
- kdxcofbo 40=0x28
- kdxcofeo 4010=0xfaa
- kdxcoavs 3970
- kdxlespl 0
- kdxlende 0
- kdxlenxt 4230421=0x408d15
- kdxleprv 4229537=0x4089a1
- kdxledsz 0 --bytes in ROWID data
- kdxlebksz 8032
- row#0[4010] flag: ----S-, lock: 2, len=2011
- col 0; len 2000; (2000): 34 34 33 20 ... 20
- col 1; len 6; (6): 00 40 8a 14 00 01
- row#1[6021] flag: ------, lock: 2, len=2011
- col 0; len 2000; (2000): 34 34 33 20 ... 20
- col 1; len 6; (6): 00 40 8c 61 00 02
唯一索引的leaf block
- Leaf block dump
- ===============
- header address 140045722856028=0x7f5eef902a5c
- kdxcolev 0
- KDXCOLEV Flags = - - -
- kdxcolok 0
- kdxcoopc 0x80: opcode=0: iot flags=--- is converted=Y
- kdxconco 1
- kdxcosdc 0
- kdxconro 3
- kdxcofbo 42=0x2a
- kdxcofeo 2002=0x7d2
- kdxcoavs 1960
- kdxlespl 0
- kdxlende 0
- kdxlenxt 4229104=0x4087f0
- kdxleprv 4229094=0x4087e6
- kdxledsz 6 --bytes in ROWID data
- kdxlebksz 8032
- row#0[6022] flag: ------, lock: 0, len=2010, data:(6): 00 40 87 ee 00 00
- col 0; len 2000; (2000): 38 38 20..20
- row#1[4012] flag: ------, lock: 0, len=2010, data:(6): 00 40 87 ee 00 01
- col 0; len 2000; (2000): 38 39 20..20
- row#2[2002] flag: ------, lock: 0, len=2010, data:(6): 00 40 87 b3 00 02
- col 0; len 2000; (2000): 39 20 20 20
总结:
- 1.因为索引条目必须是唯一的,所以对于非唯一索引的索引条目=索引键值+rowid,而唯一索引的索引条目=索引键值,ROWID存储在DATA。
- 2.Unique indexes use one byte per row less than non-unique indexes
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31347199/viewspace-2114183/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31347199/viewspace-2114183/