Bitmap Index
Bitmap Index
Bitmap index 的特點(diǎn):
1. 對(duì)于大數(shù)據(jù)量的查詢,bitmap index 能更有效的減少響應(yīng)時(shí)間
2. 減少index的占用空間
當(dāng)查詢語(yǔ)句的where 字句中包含多個(gè)column時(shí), 位圖索引最為有效. 因?yàn)樵诓樵儽碇? 那些有一個(gè)不符合所有column條件的row會(huì)直接被bitmap index 過(guò)濾掉.這樣就大大減少了響應(yīng)時(shí)間. 在多數(shù)情況下, 一般最好是針對(duì)單個(gè)column建立bitmap index 而不是組合索引.
創(chuàng)建bitmap index的時(shí)候, 必須使用 nologging 和 compute statistics.而且, bitmap index 如果有問(wèn)題, 最好是直接drop 然后重建而不是去想辦法維護(hù)它.
Cardinality? 基數(shù), 勢(shì)的集
每個(gè)column不同的值的個(gè)數(shù)叫基數(shù). distinct value. bitmap index 非常適合建在基數(shù)比較小的column上, 比如說(shuō)性別.而且如果說(shuō)某個(gè)table里面有1000000條記錄, 而某個(gè)column只有1000個(gè)不同的值, 相當(dāng)于記錄條數(shù)是0.1%. 這種情況下, 使用bitmap index也是不錯(cuò)的.
對(duì)于具有唯一約束的或者是基數(shù)比較大的column, 比如ID, 最好用普通索引, 即b-tree index.
對(duì)于fact table 和 dimension table, 可以在fact table中的外鍵上建立bitmap index.
bitmap index 和 b-tree 另外一個(gè)最大的不同在于對(duì)NULL 的處理. bitmap index 可以處理null值, 而b-tree index 則無(wú)法存儲(chǔ)NULL. 如果是bitmap index 的話, 你可以在where 字句中使用NULL, 如:
select count(*) from customer where customer_long_name is null;
此時(shí), oracle 會(huì)使用customer_long_name 上的bitmap_index快速得到值, 甚至不用去真正的access table 上的數(shù)據(jù).
但是b-tree無(wú)法做到這點(diǎn)因?yàn)槟銦o(wú)法在b-tree 上存儲(chǔ)NULL值. 所以當(dāng)你執(zhí)行:
select count(*) from customer 的時(shí)候, oracle 會(huì)自動(dòng)從NOT NULL的字段上計(jì)算總數(shù).
在partitioned table 上, Bitmap index 只能是local index 而不能是global index.
轉(zhuǎn)載于:https://www.cnblogs.com/arcer/p/3202475.html
總結(jié)
以上是生活随笔為你收集整理的Bitmap Index的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Android组件的使用:RadioBu
- 下一篇: 使用纯css做的按钮