Evaluating a star query efficiently requires specific data structures. The two key structures mentioned are B+ trees and bitmap indexes, which optimize different parts of the query.
Data Structures for Star Query Evaluation
B+ tree over CustomerKey and ProductKey: A B+ tree is a tree data structure that keeps data sorted and allows for efficient searches, insertions, and deletions. In this context, B+ trees are used on the CustomerKey and ProductKey to quickly locate dimension table records (e.g., to find the customer name for a given CustomerKey). They are particularly useful for finding individual records based on a key value.
Bitmap indexes on Sales and Product tables: A bitmap index is a specialized index that uses bit arrays (vectors of 0s and 1s) to efficiently answer queries.
Bitmap indexes on foreign key columns in Sales: A bitmap is created for each distinct foreign key value (e.g., for each ProductKey like p1, p2, p3, etc.). The bit vector has a 1 at the position corresponding to a row in the fact table that contains that specific foreign key value, and a 0 otherwise. This allows for rapid identification of fact table rows that link to a specific dimension record.
Bitmap index on Discontinued in Product: This is a simple bitmap index with two bit vectors, one for 'Yes' and one for 'No', to quickly identify all products that are discontinued.
Step-by-Step Query Evaluation Using Indexes
Let's trace the query's evaluation using these indexes:
Obtain Record Numbers for Discontinued = 'Yes': The query first uses the bitmap index on Discontinued in the Product table. This immediately returns a bit vector indicating which Product records have Discontinued = 'Yes'. The corresponding ProductKey values are then identified (e.g., p2, p4, p6). This is a highly efficient way to filter a dimension table.
Perform Join Using Bitmap Vectors: Instead of a traditional join, the database uses the bitmap indexes on the foreign key columns of the Sales table. It retrieves the bitmap vectors for the ProductKey values identified in the previous step (p2, p4, p6). The database then performs a logical OR operation on these vectors to get a final bitmap that represents all fact table rows that correspond to a discontinued product.
Find Corresponding Fact Records: The combined bitmap from step 2 is then used to directly access the relevant rows in the Sales fact table. The example shows that the vectors for p2 and p4 match (i.e., there are sales records for these products), while p6 has no corresponding sales records, so it's excluded from further processing.
Obtain Customer Keys: From the sales records that match the bitmap, the CustomerKey values are extracted. In the example, these are c2 and c3.
Use B+ Tree to Get Names: The B+ tree indexes on CustomerKey and ProductKey are then used to look up the corresponding CustomerName and ProductName from the Customer and Product tables respectively. This is a fast way to get the descriptive information for the final output.
Final Result: The final results are assembled by joining the aggregated sales data with the names found in the previous step, resulting in the final output: (cust2, prod2, 200) and (cust3, prod4, 100). This demonstrates how B+ trees and bitmap indexes work together to evaluate a star query efficiently.