The star schema and bitmap indexes are a marriage made in heaven. The bitmap indexes and their use in accelerating star schema joins is currently available in commercial databases only. Corollary: never buy a database for data warehousing that does not support star schema joins using bitmap indexes.
The advantages of bitmap indexes compared to b-tree indexes are:
- Small
- Extremely fast AND operations on individual indexes created for each low cardinality attribute
- Fast creation, no sorts required
- With Oracle, one bitmap index is created for each foreign key on the fact table: sales_transaction (calendar_key), sales_transaction (transaction_detail_key), sales_transaction (product_key), sales_organization (sales_org_key). With DB2, regular b-tree indexes are created instead. DB2 does not support direct creation of bitmap indexes, the bitmaps are created dynamically during runtime from the regular indexes and show up on the explain plan as the IXAND operator
- In addition some indexes may be created on the dimension attributes that are frequently queried: transaction_details (transaction_type), product (category), sales_organization (store), etc. With Oracle, these indexes are also bitmap indexes
5.HASH JOINThe explain plan for the star join shown above executes these steps:
4. TABLE ACCESS BY INDEX ROWID SALES_TRANSACTION
3. BITMAP AND
2. BITMAP MERGE
. BITMAP KEY ITERATION
1. TABLE ACCESS BY INDEX ROWID TRANSACTION_DETAILS
. BITMAP INDEX RANGE SCAN TRANS_DET_TRANS_TYP_BIX
. BITMAP INDEX RANGE SCAN SALES_TRANS_TRANS_DET_KEY_BIX
2. BITMAP MERGE
. BITMAP KEY ITERATION
1. TABLE ACCESS BY INDEX ROWID PRODUCT
. BITMAP INDEX RANGE SCAN PRODUCT_CATEGORY_BIX
. BITMAP INDEX RANGE SCAN SALES_TRANS_PROD_KEY_BIX
2. BITMAP MERGE
. BITMAP KEY ITERATION
1. TABLE ACCESS BY INDEX ROWID SALES_ORGANIZATION
. BITMAP INDEX RANGE SCAN SALES_ORG_STORE_BIX
. BITMAP INDEX RANGE SCAN SALES_TRANS_SALES_ORG_KEY_BIX
2. BITMAP MERGE
. BITMAP KEY ITERATION
. BUFFER SORT
1. TABLE ACCESS FULL CALENDAR
. BITMAP INDEX RANGE SCAN SALES_TRANS_CALENDAR_KEY_BIX
- Filter dimension rows using bitmap index if present. Bitmap is not required here. B-tree index is used if present or full table scan is done if no indexes are viable
- BITMAP MERGE - create a new bitmap by performing intersection of: the limited row set returned by the dimension WHERE clause and the full bitmap index present on the fact foreign key for the dimension
- BITMAP AND - execute AND operation on all the bitmaps returned by step 2 after completion of all the respective dimension joins with fact bitmaps
- Fact lookup - get only the fact rows for the rowids returned by the result of step 3
- Hash join only the fact rows filtered in step 4 with the dimension rows
So far so good, the biggest disadvantage with using bitmaps is that they are not amenable to updates. In a data warehousing environment this is not a big concern as the indexes are preferably dropped before data load and created once the load is complete.