大家聽到這個詞,一定就想到了節省硬碟空間吧。沒錯,它就是用來幹這個的,但是向外延伸一下,它不僅可以節省硬碟空間,更可以節省頻寬以及記憶體的使用(cpu有一點點損耗因為需要更多的計算取值操作,但是鑒於大多數環境下cpu都有空閑,所以也可以忽略了)。
Basiccompression這個功能從9i開始就有提供,11gr1開始提供了新的壓縮功能,即OLTP compression。Basic compression是包括在EE版本中的,不需要額外收費,但是OLTP compression則需要額外的Oracle Advanced Compression optionlicense。進階?想用?掏錢吧。
下面的圖片能夠協助你簡單瞭解壓縮塊的原理:
簡單來說,就是在block中會存有特殊的資料結構,symbol table。
Symboltable dump出來的內容如下所示:
tab 0, row 0, @0x1da4 tl: 7 fb: --H-FL-- lb: 0x0 cc: 12 col 0:*NULL* col 1: [5] 56 41 4c 49 44 col 2: [1] 4e col 3:*NULL* col 4: [1] 4e col 5: [1] 4e col 6: [3] 53 59 53 col 7: [7] 78 6f 0a 1e 0d 39 19 col 8:[19] 32 30 31 31 2d 31 30 2d 33 30 3a 3132 3a 35 36 3a 32 34 col 9: [2] c1 05 col 10: [ 5] 49 4e 44 45 58 col 11: [ 7] 78 6f 0a 1e 0d 39 19 bindmp: 00 2a 0c 15 20 24 22
真正的資料內容如下所示:
tab 0, row 0, @0x1da4 tl: 7 fb: --H-FL-- lb: 0x0 cc: 12 col 0:*NULL* col 1: [5] 56 41 4c 49 44 col 2: [1] 4e col 3:*NULL* col 4: [1] 4e col 5: [1] 4e col 6: [3] 53 59 53 col 7: [7] 78 6f 0a 1e 0d 39 19 col 8:[19] 32 30 31 31 2d 31 30 2d 33 30 3a 3132 3a 35 36 3a 32 34 col 9: [2] c1 05 col 10: [ 5] 49 4e 44 45 58 col 11: [ 7] 78 6f 0a 1e 0d 39 19 bindmp: 00 2a 0c 15 20 24 22
有點類似於clustertable的block結構。簡單來說就是只將block重複的內容存放一份到symbol table中,真正的表row piece引用存放在symbol table中的重複的內容。因為Basiccompression和OLTPcompresssion都是塊內壓縮,所以就算擁有重複的內容,但是如果不在同一個塊記憶體放,還是無法達到壓縮的效果。其原理先介紹到這,如果想要深入研究,可以參考老熊的blog。
Oracle壓縮表資料區塊格式解析:
http://www.laoxiong.net/dissect_compressed_block_part1.html