2-2 Copyright 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Explain the difference between a star schema and a snowflake schema Describe a star transformation Control initialization parameters relating to star queries 2-3 Copyright 2005, Oracle. All rights reserved. Star Schema Model
PROD_ID PROD_NAME PROD_DESC 2-5 Copyright 2005, Oracle. All rights reserved. Snowflake Schema Model Dimension table Dimension table Dimension table Dimension table Fact table CHANNELS TIMES PRODUCTS SALES (amount,cost, quantity_sold) SUPPLIERS CUSTOMERS COUNTRIES PROMOTIONS 2-7 Copyright 2005, Oracle. All rights reserved. Creating Dimensions CREATE DIMENSION products_dim LEVEL product IS (products.prod_id) LEVEL subcategory IS (products.prod_subcategory) LEVEL category IS (products.prod_category) ...
CATEGORY
SUBCATEGORY PRODUCT 2-8 Copyright 2005, Oracle. All rights reserved. Creating Hierarchy Relationships
CREATE DIMENSION products_dim ... HIERARCHY prod_rollup ( product CHILD OF subcategory CHILD OF category) ATTRIBUTE product DETERMINES (products.prod_name, products.prod_desc, prod_weight_class, prod_unit_of_measure, prod_pack_size, prod_status, prod_list_price, prod_min_price) ATTRIBUTE subcategory DETERMINES (prod_subcategory, prod_subcategory_desc) ATTRIBUTE category DETERMINES (prod_category, prod_category_desc); 2-9 Copyright 2005, Oracle. All rights reserved. Third Normal Form Schemas CUSTOMERS PRODUCTS ORDERS ORDER ITEMS 2-10 Copyright 2005, Oracle. All rights reserved. Tuning Star Queries A bitmap index should be built on each of the foreign key columns of the fact table or tables. Set STAR_TRANSFORMATION_ENABLED to TRUE. This enables an important optimizer feature for star queries. It is set to FALSE by default for backward compatibility. Analyze all corresponding objects. select .
2-11 Copyright 2005, Oracle. All rights reserved. Star Transformation Star transformation is an optimization technique that implicitly rewrites the original star query. A star query is processed in two phases: The necessary rows are retrieved from the fact table, creating a result set. The result set is then joined to the dimension tables. Star transformation requires that there be a single- column bitmap index on every join column of the fact table. 2-12 Copyright 2005, Oracle. All rights reserved. Contrasting Star Transformation and Conventional Joins Conventional joins: Cause each involved dimension table to be successively joined to the fact table Cause costly row-culling operations for each successive dimension table join Employ resource-consuming hash joins for row culling Star transformation: Joins all involved dimension tables before the fact table is accessed Produces a composite set of row IDs before accessing the fact table Employs more efficient Boolean join operations 2-13 Copyright 2005, Oracle. All rights reserved. Star Transformation Hints STAR_TRANSFORMATION hint: Use the best plan containing a star transformation, if there is one. FACT(<table_name>) hint: The hinted table should be considered as the fact table in the context of a star transformation query. NO_FACT (<table_name>) hint: The hinted table should not be considered as the fact table in the context of a star transformation. FACT and NO_FACT hints are useful for star transformation queries containing more than one fact table. 2-14 Copyright 2005, Oracle. All rights reserved. Star Query: Example SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc, SUM(s.amount_sold) sales_amount FROM sales s,times t,customers c,channels ch WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id AND s.channel_id = ch.channel_id AND c.cust_state_province = 'CA' AND ch.channel_desc IN ('Internet','Catalog') AND t.calendar_quarter_desc IN ('1999-Q1','1999-Q2') GROUP BY ch.channel_class, c.cust_city, t.calendar_quarter_desc; 2-15 Copyright 2005, Oracle. All rights reserved. Star Transformation: Rewrite Example SELECT s.amount_sold FROM sales s WHERE time_id IN (SELECT time_id FROM times WHERE calendar_quarter_desc IN('1999-Q1','1999-Q2')) AND cust_id IN (SELECT cust_id FROM customers WHERE cust_state_province = 'CA') AND channel_id IN(SELECT channel_id FROM channels WHERE channel_desc IN ('Internet','Catalog')); 2-17 Copyright 2005, Oracle. All rights reserved. Star Transformation Execution Plan SORT GROUP BY HASH JOIN HASH JOIN TABLE ACCESS BY INDEX ROWID SALES BITMAP CONVERSION TO ROWIDS BITMAP AND BITMAP MERGE BITMAP KEY ITERATION BUFFER SORT TABLE ACCESS FULL CHANNELS BITMAP INDEX RANGE SCAN SALES_CHANNELS_BX BITMAP MERGE BITMAP KEY ITERATION BUFFER SORT TABLE ACCESS FULL TIMES BITMAP INDEX RANGE SCAN SALES_TIMES_BX TABLE ACCESS FULL CHANNELS TABLE ACCESS FULL TIMES 2-18 Copyright 2005, Oracle. All rights reserved. Retrieving Fact Rows from One Dimension BITMAP KEY ITERATION Dimension table access Fact table bitmap access BITMAP MERGE One bitmap is produced. 2-19 Copyright 2005, Oracle. All rights reserved. Retrieving Fact Rows from All Dimensions
Multiple bitmaps are ANDed together. Result set MERGE i
BITMAP AND MERGE 1 MERGE n BITMAP conversion to row IDs 2-20 Copyright 2005, Oracle. All rights reserved. Joining the Result Set with Dimensions HASH JOIN Dimension 1 table access Fact table access from result set Dimension n table access HASH JOIN Dimension i table access HASH JOIN 2-21 Copyright 2005, Oracle. All rights reserved. Star Transformation: Further Optimization In a star transformation execution plan, dimension tables are accessed twice: once for each phase. This may be a performance issue with big dimension tables, and bad selectivity. If the cost is cheaper, a temporary table may be created and used instead of accessing the same dimension table twice. Done automatically, transparent to the end-user The following PLAN_TABLE columns show temporary tables information: OBJECT_NAME OTHER 2-22 Copyright 2005, Oracle. All rights reserved. Bitmap Index Storage Performance For each existing bitmap index Set COMPATIBLE to 10.2.0.0 Severe slowdown before raising COMPATIBLE? Rebuild Slowdown after raising COMPATIBLE? Yes Yes Create new bitmap indexes 2-23 Copyright 2005, Oracle. All rights reserved. Static Partition Pruning and Star Query Pruning is determined at parse time. In most cases, fact tables are never directly filtered. SELECT prod_subcategory, cust_city, sum(amount_sold) FROM sales s, products p, customers c WHERE s.prod_id = p.prod_id AND s.cust_id = c.cust_id AND prod_category IN ('Men','Women') AND cust_year_of_birth ='1968' AND s.time_id BETWEEN TO_DATE('12.01.1999','mm.dd.yyyy') AND TO_DATE('12.31.1999','mm.dd.yyyy') GROUP BY prod_subcategory,cust_city; 2-24 Copyright 2005, Oracle. All rights reserved. Static Partition Pruning Plan: Example SORT (GROUP BY) HASH JOIN HASH JOIN TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'SALES' [12] BITMAP CONVERSION (TO ROWIDS) BITMAP AND BITMAP MERGE BITMAP KEY ITERATION TABLE ACCESS FULL OF 'CUSTOMERS' BITMAP INDEX (RANGE SCAN) OF 'SALES_C_BX' [12] BITMAP MERGE BITMAP INDEX (RANGE SCAN) OF 'SALES_T_BX' [12] BITMAP MERGE BITMAP KEY ITERATION TABLE ACCESS (FULL) OF 'PRODUCTS' BITMAP INDEX (RANGE SCAN) OF 'SALES_P_BX' [12] TABLE ACCESS (FULL) OF 'CUSTOMERS' TABLE ACCESS (FULL) OF 'PRODUCTS' 2-25 Copyright 2005, Oracle. All rights reserved. Dynamic Partition Pruning and Star Query Pruning is determined at run time. Commonly used query form: SELECT prod_subcategory, sum(amount_sold) FROM sales s, products p, times t WHERE s.prod_id = p.prod_id AND s.time_id = t.time_id AND t.calendar_month_number = 12 AND t.calendar_year = 1999 AND prod_category IN ('Men','Women') GROUP BY prod_subcategory; 2-26 Copyright 2005, Oracle. All rights reserved. Dynamic Partition Pruning Determination During execution, the list of eligible partitions is computed. The corresponding recursive SQL can be retrieved from the OTHER column of PLAN_TABLE. SELECT DISTINCT TBL$OR$IDX$PART$NUM( "SALES",0,d#,p#,"TIME_ID") FROM (SELECT /*+ SEMIJOIN_DRIVER */ T.TIME_ID FROM TIMES T WHERE T.CALENDAR_MONTH_NUMBER = 12 AND T.CALENDAR_YEAR=1999) ORDER BY 1; 2-27 Copyright 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Distinguish star schemas and snowflake schemas Interpret a star transformation execution plan Set the STAR_TRANSFORMATION initialization parameter Use dynamic partition pruning 2-28 Copyright 2005, Oracle. All rights reserved. Practice 2: Overview
This practice covers the following topics: Analyzing star transformation execution plans Understanding temporary table optimization for star transformation