有關Bitmap Join Indexes的精彩帖二
全文摘自http://ningoo.itpub.net/post/2149/223616
Bitmap index的主要思想就是,針對每一個可能的值x,建立一個或一組點陣圖對映,每個bit為1代表這個位置的值等於x,為0則不等於x。而每個位置都可以直接對映到某一行的rowid。由於在執行DML操作時,鎖定的是整個bitmap,而不是bitmap中的某個位,所以bitmap index對於併發DML的效能很差,而且頻繁的DML操作會使得bitmap index的空間效率大打折扣,所以OLTP系統並不合適使用bitmap index。對於基本沒有DML操作,有大量ad hoc查詢的Data warehouse環境則相當有效。
從oracle9i 起,oracle又引進了一種新的索引型別:bitmap join index。和bitmap index建立在單個table上不同,bitmap join index是基於多表連線的,連線條件要求是等於的內連線(equi-inner join)。對於資料倉儲而言,較普遍的是Fact table的外來鍵列和相關的Dimension table的主鍵列的連線操作。
Bitmap join index能夠消除查詢中的連線操作,因為它實際上已經將連線的結果儲存在索引當中了。而且,相對於在表的連線列上建普通bitmap index來說,bitmap join index需要更少的儲存空間。
同樣的基於連線的Metarialized view也可以用來消除連線操作。但bitmap join index比起物化檢視來更有效率,因為透過bitmap join index可以直接將基於索引列的查詢對應到事實表的rowid。
以oracle的sample schema SH中的sales和customers表做個例子
1.建立基於維度表中一個列的bitmap join index
create bitmap index sales_cust_gender_bjix
on sales(customers.cust_gender)
from sales,customers
where sales.cust_id=customers;
建立這樣的bitmap join index後,下面的查詢就可以從index中直接得到結果,而不再需要連線sales和custmoers兩張表來獲得結果了。相當於根據連線條件,將customers表中的cust_gender列儲存到sales表中了。
select sum(sales.amount_sold)
from sales,customers
where sales.cust_id,customers.cust_id
and customers.cust_gender='M';
透過將bitmap join index dump出來可以看到,實際上,索引是按照customers.cust_gender分成2個點陣圖,每個點陣圖對映到sales表的ROWID。所以根據customers.cust_gender來過濾連線結果時,從索引中可以直接得到目標資料在sales中的rowid,無須執行join操作了。
一個可能的執行計劃如下:
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3751 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 PARTITION RANGE (ALL)
3 2 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'SALES' (Cost=3751 Card=508136 Bytes=4573220)
4 3 BITMAP CONVERSION (TO ROWIDS)
5 4 BITMAP INDEX (SINGLE VALUE) OF 'IX_BITMAP'
2.建立基於一個維度表中多個列的bitmap join index
create bitmap index sales_cust_ms_bjix
on sales(customers.cust_gender,customers.cust_id)
from sales,customers
where sales.cust_id=customers.cust_id;
3.建立多個維度表到一個事實表的bitmap join indexcreate bitmap index sales_c_gender_p_cat_bjix
on sales(customers.cust_gender,products.prod_category)
from sales,customers,products
where sales.cust_id=customers.cust_id
and sales.prod_id=products.prod_id;
4.建立基於snowflake schme的bitmap join index
雪花模型的維度表被規範化為多個小表,也就是建index的時候需要額外連線其他幾個表
create bitmap index sales_co_country_name_bjix
on sales(countries.country_name)
from sales,countries,customers
where sales.country_id=countries.country_id
and sales.cust_id=customers.cust_id;
Bitmap join index的一些限制條件
只支援CBO
只能是equi-inner連線,任何外連線都無法使用bitmap join index
多個連線條件只能是AND關係
只能在fact table上執行並行DML。如果在dimension table上執行並行DML,會導致索引變為unusable狀態。
不同的事務中,只能併發更新一個表
在From字句中,任何一個表都不能出現兩次
在索引組織表(IOT)和臨時表上不能建立bitmap join index
索引只能基於dimenion table中的列
維度表用於連線的列只能是主鍵列或者是有唯一約束的列。
SQL> create bitmap index sales_cust_gender_bjix
2 on sales(customers.cust_gender)
3 from sales,customers
4 where sales.cust_id=customers.cust_id;
from sales,customers
*
ERROR at line 3:
ORA-25954: missing primary key or unique constraint on dimension
如果維度表的主鍵是組合主鍵,那麼連線條件需要是全部主鍵列都參與
其他對於bitmap index的限制條件同樣使用於bitmap join index,比如在分割槽表上只能是local,不能是global。
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10599713/viewspace-983036/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [轉帖]基礎一:健康網站的關鍵指標有哪些?網站指標
- 大資料下的Distinct Count(二):Bitmap篇大資料
- join、inner join、left join、right join、outer join的區別
- MySQL筆記-左連線的使用(left join有關聯的多表查詢)MySql筆記
- 【SQL】13 SQL 別名、SQL 連線(JOIN)、SQL INNER JOIN 關鍵字、SQL LEFT JOIN 關鍵字、SQL RIGHT JOIN 關鍵字、SQL FULL OUTER JSQL
- 翻譯(九)——Clustered Indexes: Stairway to SQL Server Indexes Level 3IndexAISQLServer
- Join關聯聯絡案例
- MySQL表關聯join方式MySql
- [轉帖]netstat -st輸出解析(二)
- android 關於Bitmap壓縮處理解析Android
- [20180510]20 Indexes.txtIndex
- 與控制檔案有關的恢復(二)
- Mysql join 的本質,Nested Loop Join 和 Hash JoinMySqlOOP
- sql的left join 、right join 、inner join之間的區別SQL
- mysql中的left join、right join 、inner join的詳細用法MySql
- Android中的BitmapAndroid
- [20180705]關於hash join 2.txt
- MySQL LEFT JOIN/ INNER JOIN/RIGHT JOINMySql
- PostgreSQL DBA(45) - Hypothetical Indexes in PostgreSQLSQLIndex
- c# svg轉Bitmap Bitmap轉ImageSourceC#SVG
- Clickhouse的bitmap函式函式
- Jedis bitmap
- SQL JOIN 中 on 與 where 有何區別SQL
- 一張圖搞定七種 JOIN 關係
- [轉帖]晶片相關-- Cpu歷史--intel系列晶片Intel
- [轉帖]晶片相關-- Cpu歷史--AMD系列晶片
- MySQL 8 新特性之Invisible IndexesMySqlIndex
- Inner Join, Left Outer Join和Association的區別
- [轉帖]Redis相關的核心引數解釋與設定Redis
- 實現簡單的BitMap
- Redis的Bitmap、HyperLogLog和GeoRedis
- Bitmap回收—Canvas: trying to use a recycled bitmap android.graphicsCanvasAndroid
- java的join()方法Java
- MySQL JOIN的使用MySql
- 理解Android BitmapAndroid
- Android Bitmap 使用Android
- BitMap介紹
- mysql left join轉inner joinMySql
- [20202117]Function based indexes and cursor sharing.txtFunctionIndex