Presentation is loading. Please wait.

Presentation is loading. Please wait.

10 Copyright © 2005, Oracle. All rights reserved. Dimensions.

Similar presentations


Presentation on theme: "10 Copyright © 2005, Oracle. All rights reserved. Dimensions."— Presentation transcript:

1 10 Copyright © 2005, Oracle. All rights reserved. Dimensions

2 10-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Create dimensions Validate dimension data View dimension definition information

3 10-3 Copyright © 2005, Oracle. All rights reserved. What Are Dimensions? Data dictionary structures that define hierarchies between pairs of column sets Used with materialized views for query rewrite Superset of referential constraints: –Normalized dimensions: Each child-side row joins with one and only one parent-side row. –Denormalized dimensions: Child-side columns uniquely determine the parent-side columns. Never enforced, but can be validated Enable additional query rewrites without the use of constraints

4 10-4 Copyright © 2005, Oracle. All rights reserved. Dimensions and Hierarchies MONTH_NAME Week Season ALL Level key Additional attribute Hierarchy CALENDAR_ROLLUP MONTH Level key attribute Year Quarter Sales date Month TIME_DIM dimension

5 10-5 Copyright © 2005, Oracle. All rights reserved. Full Notes Page

6 10-6 Copyright © 2005, Oracle. All rights reserved. Dimension Table: Example SQL> SELECT * FROM time; TIME_ID MONTH MONTH_NAM QUARTER YEAR JAN-02 M1_02 January02 Q1_ JAN-02 M1_02 January02 Q1_ JAN-02 M1_02 January02 Q1_ MAR-02 M2_02 March02 Q1_ DEC-02 M12_02 December02 Q4_ DEC-02 M12_02 December02 Q4_ Table used in examples in the lesson:

7 10-7 Copyright © 2005, Oracle. All rights reserved. Benefits of Dimensions SELECT year, sum(amount_sold) AS sumamt FROM time t, sales s WHERE t.time_id=s.time_id GROUP BY year; SELECT year, sum(sumamt) FROM sumsales mv, (SELECT DISTINCT month, year FROM times) v WHERE v.month = mv.month GROUP BY year; CREATE MATERIALIZED VIEW sumsales AS SELECT month, sum(amount_sold) AS sumamt FROM time t, sales s WHERE t.time_id = s.time_id GROUP BY month; Materialized view created User executes query Query rewritten

8 10-8 Copyright © 2005, Oracle. All rights reserved. Defining Dimensions and Hierarchies CREATE DIMENSION time_dim LEVEL sdate IS time.sdate LEVEL month IS time.month LEVEL qtr IS time.quarter LEVEL yr IS time.year HIERARCHY calendar_rollup ( sdate CHILD OF month CHILD OF qtr CHILD OF yr ) ATTRIBUTE month DETERMINES time.month_name; yr qtr month sdate

9 10-9 Copyright © 2005, Oracle. All rights reserved. Specifying the SKIP WHEN NULL Clause CREATE DIMENSION SALE_DATA_DIM LEVEL CUSTOMER IS SALE_DATA.CUST_ID LEVEL CITY IS SALE_DATA.CITY LEVEL STATE IS SALE_DATA.STATE SKIP WHEN NULL LEVEL COUNTRY IS SALE_DATA.COUNTRY HIERARCHY GEOG_ROLLUP (CUSTOMER CHILD OF CITY CHILD OF STATE CHILD OF COUNTRY) CUST_ID CITY STATE COUNTRY Washington, D.C. USA No state

10 10-10 Copyright © 2005, Oracle. All rights reserved. Full Notes Page

11 10-11 Copyright © 2005, Oracle. All rights reserved. Creating Dimensions Using Enterprise Manager create_dimension.gif

12 10-12 Copyright © 2005, Oracle. All rights reserved. Dimensions Based on Multiple Tables CREATE DIMENSION customers_dim LEVEL customer IS customers.cust_id LEVEL city IS customers.cust_city LEVEL state IS customers.cust_state_province LEVEL country IS countries.country_id LEVEL subregion IS countries.country_subregion LEVEL region IS countries.country_region HIERARCHY geo_rollup ( customer CHILD OF city CHILD OF state CHILD OF country CHILD OF subregion CHILD OF region JOIN KEY (customers.country_id) REFERENCES country) ATTRIBUTE customer DETERMINES (cust_first_name, cust_last_name) ATTRIBUTE country DETERMINES countries.country_name;

13 10-13 Copyright © 2005, Oracle. All rights reserved. Dimensions with Multiple Hierarchies CAL hierarchy WEEK hierarchy YEAR QUARTER MONTH DAY YEAR WEEK DAY

14 10-14 Copyright © 2005, Oracle. All rights reserved. Dimensions and Privileges CREATE DIMENSION CREATE ANY DIMENSION SELECT object privilege on each referenced object ALTER ANY DIMENSION DROP ANY DIMENSION

15 10-15 Copyright © 2005, Oracle. All rights reserved. Dimension Restrictions Two levels cannot have the same column set. Columns of a hierarchy level cannot be associated with more than one dimension. A hierarchy level cannot be a child of itself. All level key attributes for one level must belong to the same table. The JOIN clause is required if columns of different levels come from different tables. All additional attributes for one level key must belong to the same table. It is not possible to create dimensions based on views.

16 10-16 Copyright © 2005, Oracle. All rights reserved. Using VALIDATE_DIMENSION to Verify Relationships in a Dimension DBMS_DIMENSION.VALIDATE_DIMENSION ('SH.TIMES_DIM',TRUE,TRUE,'ver times_dim'); Check that levels are non-null Check only new rows in the tables Dimension owner and name User-supplied identifier

17 10-17 Copyright © 2005, Oracle. All rights reserved. Verifying Relationships in a Dimension DBMS_DIMENSION.VALIDATE_DIMENSION ('SH.CHANNELS_DIM', false, true, 'ver chan_dim'); SELECT * FROM sh.channels WHERE rowid IN (SELECT bad_rowid FROM dimension_exceptions WHERE statement_id = 'ver chan_dim'); CHANNEL_ID CHANNEL_DESC CHANNEL_CLASS S Direct Sales Direct S Security

18 10-18 Copyright © 2005, Oracle. All rights reserved. Viewing Dimensions Using Enterprise Manager view_dimension.gif

19 10-19 Copyright © 2005, Oracle. All rights reserved. Viewing Dimensions in the Data Dictionary DBA_DIMENSIONS DBA_DIM_LEVELS DBA_DIM_LEVEL_KEY DBA_DIM_ATTRIBUTES DBA_DIM_HIERARCHIES DBA_DIM_CHILD_OF DBA_DIM_JOIN_KEY

20 10-20 Copyright © 2005, Oracle. All rights reserved. Viewing the Definition of a Dimension SQL> SET SERVEROUTPUT ON FORMAT WRAPPED SQL> EXECUTE DBMS_DIMENSION.DESCRIBE_DIMENSION ('sh.channels_dim'); DIMENSION SH.CHANNELS_DIM LEVEL CHANNEL IS SH.CHANNELS.CHANNEL_ID LEVEL CHANNEL_CLASS IS SH.CHANNELS.CHANNEL_CLASS_ID LEVEL CHANNEL_TOTAL IS SH.CHANNELS.CHANNEL_TOTAL_ID HIERARCHY CHANNEL_ROLLUP ( CHANNEL CHILD OF CHANNEL_CLASS CHILD OF CHANNEL_TOTAL ) ATTRIBUTE CHANNEL LEVEL CHANNEL DETERMINES SH.CHANNELS.CHANNEL_DESC ATTRIBUTE CHANNEL_CLASS LEVEL CHANNEL_CLASS DETERMINES SH.CHANNELS.CHANNEL_CLASS ATTRIBUTE CHANNEL_TOTAL LEVEL CHANNEL_TOTAL DETERMINES SH.CHANNELS.CHANNEL_TOTAL

21 10-21 Copyright © 2005, Oracle. All rights reserved. Dimension Invalidation Invalidation is done automatically when related objects are altered. Verify a dimensions status through Enterprise Manager or the INVALID column of DBA_DIMENSIONS. Use the ALTER DIMENSION … COMPILE command to revalidate a dimension.

22 10-22 Copyright © 2005, Oracle. All rights reserved. Drop a dimension as follows: Does not invalidate materialized views that use relationships specified in the dimension Dropping Dimensions DROP DIMENSION channels_dim;

23 10-23 Copyright © 2005, Oracle. All rights reserved. Create the materialized view using the attribute LEVEL clause: Selectively drop a column: Selectively Dropping Dimension Components ALTER DIMENSION product_dim DROP ATTRIBUTE att LEVEL prod_id COLUMN prod_status; CREATE DIMENSION product_dim LEVEL prod_id IS (products.prod_id) ATTRIBUTE att LEVEL prod_id DETERMINES prod_name, prod_status;

24 10-24 Copyright © 2005, Oracle. All rights reserved. Constraints or Dimensions? For normalized dimensions, use: – PK/NOT NULL FK relationships as long as possible, or –Dimensions For denormalized dimensions, use dimensions. Joins between dimension and fact tables should be materialized by: – PK/NOT NULL FK relationships: NOVALIDATE RELY flags if validation is of concern, and/or –Dimensions, or –Joins-only materialized views defined with outer joins Always make sure dimensions are valid if used.

25 10-25 Copyright © 2005, Oracle. All rights reserved. Full Notes Page

26 10-26 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Distinguish between dimensions and constraints Create dimensions Validate dimension data View dimension definitions

27 10-27 Copyright © 2005, Oracle. All rights reserved. Practice 10: Overview This practice covers the following topics: Creating dimensions on multiple tables Validating dimensions

28 10-28 Copyright © 2005, Oracle. All rights reserved.


Download ppt "10 Copyright © 2005, Oracle. All rights reserved. Dimensions."

Similar presentations


Ads by Google