Tải bản đầy đủ (.pdf) (806 trang)

Oracle Database Data Warehousing Guide

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.79 MB, 806 trang )

Oracle® Database
Data Warehousing Guide
10g Release 1 (10.1)
Part No. B10736-01

December 2003


Oracle Database Data Warehousing Guide, 10g Release 1 (10.1)
Part No. B10736-01
Copyright © 2001, 2003 Oracle Corporation. All rights reserved.
Primary Author:

Paul Lane

Contributing Authors:

Viv Schupmann, Ingrid Stuart (Change Data Capture)

Contributors: Patrick Amor, Hermann Baer, Mark Bauer, Subhransu Basu, Srikanth Bellamkonda,
Randy Bello, Tolga Bozkaya, Lucy Burgess, Rushan Chen, Benoit Dageville, John Haydu, Lilian Hobbs,
Hakan Jakobsson, George Lumpkin, Alex Melidis, Valarie Moore, Cetin Ozbutun, Ananth Raghavan,
Jack Raitto, Ray Roccaforte, Sankar Subramanian, Gregory Smith, Murali Thiyagarajan, Ashish Thusoo,
Thomas Tong, Jean-Francois Verrier, Gary Vincent, Andreas Walter, Andy Witkowski, Min Xiao,
Tsae-Feng Yu
The Programs (which include both the software and documentation) contain proprietary information of
Oracle Corporation; they are provided under a license agreement containing restrictions on use and
disclosure and are also protected by copyright, patent and other intellectual and industrial property
laws. Reverse engineering, disassembly or decompilation of the Programs, except to the extent required
to obtain interoperability with other independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems


in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this
document is error-free. Except as may be expressly permitted in your license agreement for these
Programs, no part of these Programs may be reproduced or transmitted in any form or by any means,
electronic or mechanical, for any purpose, without the express written permission of Oracle Corporation.
If the Programs are delivered to the U.S. Government or anyone licensing or using the programs on
behalf of the U.S. Government, the following notice is applicable:
Restricted Rights Notice Programs delivered subject to the DOD FAR Supplement are "commercial
computer software" and use, duplication, and disclosure of the Programs, including documentation,
shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement.
Otherwise, Programs delivered subject to the Federal Acquisition Regulations are "restricted computer
software" and use, duplication, and disclosure of the Programs shall be subject to the restrictions in FAR
52.227-19, Commercial Computer Software - Restricted Rights (June, 1987). Oracle Corporation, 500
Oracle Parkway, Redwood City, CA 94065.
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy, and other measures to ensure the safe use of such applications if the Programs are used for
such purposes, and Oracle Corporation disclaims liability for any damages caused by such use of the
Programs.
Oracle is a registered trademark, and Express, Oracle8i, Oracle9i, Oracle Store, PL/SQL, Pro*C, and
SQL*Plus are trademarks or registered trademarks of Oracle Corporation. Other names may be
trademarks of their respective owners.


Contents
Send Us Your Comments .............................................................................................................. xxix
Preface........................................................................................................................................................ xxxi
Audience ............................................................................................................................................ xxxii
Organization...................................................................................................................................... xxxii
Related Documentation .................................................................................................................. xxxiv
Conventions....................................................................................................................................... xxxv

Documentation Accessibility ....................................................................................................... xxxviii

What's New in Oracle Database? ............................................................................................. xxxix
Oracle Database 10g Release 1 (10.1) New Features in Data Warehousing ..................................

xl

Volume 1
Part I
1

Concepts

Data Warehousing Concepts
What is a Data Warehouse?...............................................................................................................
Subject Oriented............................................................................................................................
Integrated.......................................................................................................................................
Nonvolatile ....................................................................................................................................
Time Variant..................................................................................................................................
Contrasting OLTP and Data Warehousing Environments.....................................................
Data Warehouse Architectures .........................................................................................................

1-2
1-2
1-2
1-3
1-3
1-3
1-5


iii


Data Warehouse Architecture (Basic) ........................................................................................ 1-5
Data Warehouse Architecture (with a Staging Area) .............................................................. 1-6
Data Warehouse Architecture (with a Staging Area and Data Marts) ................................. 1-6

Part II
2

Logical Design

Logical Design in Data Warehouses
Logical Versus Physical Design in Data Warehouses ..................................................................
Creating a Logical Design .................................................................................................................
Data Warehousing Schemas..............................................................................................................
Star Schemas ..................................................................................................................................
Other Schemas...............................................................................................................................
Data Warehousing Objects................................................................................................................
Fact Tables......................................................................................................................................
Creating a New Fact Table ...................................................................................................
Dimension Tables .........................................................................................................................
Hierarchies..............................................................................................................................
Typical Dimension Hierarchy..............................................................................................
Unique Identifiers .........................................................................................................................
Relationships .................................................................................................................................
Example of Data Warehousing Objects and Their Relationships..........................................

Part III
3


Physical Design

Physical Design in Data Warehouses
Moving from Logical to Physical Design.......................................................................................
Physical Design ...................................................................................................................................
Physical Design Structures ..........................................................................................................
Tablespaces ....................................................................................................................................
Tables and Partitioned Tables.....................................................................................................
Table Compression................................................................................................................
Views ..............................................................................................................................................
Integrity Constraints ....................................................................................................................
Indexes and Partitioned Indexes ................................................................................................

iv

2-2
2-2
2-3
2-4
2-4
2-5
2-5
2-5
2-6
2-6
2-7
2-7
2-7
2-8


3-2
3-2
3-3
3-4
3-4
3-5
3-5
3-5
3-6


Materialized Views....................................................................................................................... 3-6
Dimensions .................................................................................................................................... 3-6

4

Hardware and I/O Considerations in Data Warehouses
Overview of Hardware and I/O Considerations in Data Warehouses .....................................
Configure I/O for Bandwidth not Capacity.............................................................................
Stripe Far and Wide......................................................................................................................
Use Redundancy...........................................................................................................................
Test the I/O System Before Building the Database .................................................................
Plan for Growth ............................................................................................................................
Storage Management..........................................................................................................................

5

4-2
4-2

4-3
4-3
4-4
4-4
4-4

Parallelism and Partitioning in Data Warehouses
Overview of Parallel Execution........................................................................................................
When to Implement Parallel Execution.....................................................................................
Granules of Parallelism .....................................................................................................................
Block Range Granules ..................................................................................................................
Partition Granules.........................................................................................................................
Partitioning Design Considerations ...............................................................................................
Types of Partitioning....................................................................................................................
Partitioning Methods ............................................................................................................
Index Partitioning..................................................................................................................
Performance Issues for Range, List, Hash, and Composite Partitioning ......................
Partitioning and Table Compression .......................................................................................
Table Compression and Bitmap Indexes .........................................................................
Example of Table Compression and Partitioning...........................................................
Partition Pruning ........................................................................................................................
Pruning Using DATE Columns.........................................................................................
Avoiding I/O Bottlenecks..................................................................................................
Partition-Wise Joins....................................................................................................................
Full Partition-Wise Joins.....................................................................................................
Partial Partition-wise Joins.................................................................................................
Benefits of Partition-Wise Joins .........................................................................................
Performance Considerations for Parallel Partition-Wise Joins.....................................
Partitioning and Subpartitioning Columns and Keys ..........................................................


5-2
5-2
5-3
5-3
5-4
5-4
5-4
5-5
5-9
5-9
5-16
5-17
5-18
5-19
5-20
5-20
5-20
5-20
5-26
5-28
5-29
5-30

v


Partition Bounds for Range Partitioning .................................................................................
Comparing Partitioning Keys with Partition Bounds....................................................
MAXVALUE.........................................................................................................................
Nulls ......................................................................................................................................

DATE Datatypes .................................................................................................................
Multicolumn Partitioning Keys .........................................................................................
Implicit Constraints Imposed by Partition Bounds ........................................................
Index Partitioning .......................................................................................................................
Local Partitioned Indexes ...................................................................................................
Global Partitioned Indexes.................................................................................................
Summary of Partitioned Index Types...............................................................................
The Importance of Nonprefixed Indexes .........................................................................
Performance Implications of Prefixed and Nonprefixed Indexes ................................
Guidelines for Partitioning Indexes..................................................................................
Physical Attributes of Index Partitions.............................................................................

6

Indexes
Using Bitmap Indexes in Data Warehouses...................................................................................
Benefits for Data Warehousing Applications ..........................................................................
Cardinality .....................................................................................................................................
Bitmap Indexes and Nulls ...........................................................................................................
Bitmap Indexes on Partitioned Tables .......................................................................................
Using Bitmap Join Indexes in Data Warehouses......................................................................
Four Join Models for Bitmap Join Indexes.........................................................................
Bitmap Join Index Restrictions and Requirements ...........................................................
Using B-Tree Indexes in Data Warehouses ..................................................................................
Using Index Compression ...............................................................................................................
Choosing Between Local Indexes and Global Indexes .............................................................

7

6-2

6-2
6-3
6-5
6-6
6-6
6-6
6-9
6-10
6-10
6-11

Integrity Constraints
Why Integrity Constraints are Useful in a Data Warehouse ......................................................
Overview of Constraint States..........................................................................................................
Typical Data Warehouse Integrity Constraints .............................................................................
UNIQUE Constraints in a Data Warehouse .............................................................................
FOREIGN KEY Constraints in a Data Warehouse...................................................................

vi

5-31
5-31
5-31
5-32
5-32
5-33
5-33
5-33
5-34
5-37

5-39
5-40
5-40
5-41
5-42

7-2
7-3
7-3
7-4
7-5


RELY Constraints .........................................................................................................................
Integrity Constraints and Parallelism........................................................................................
Integrity Constraints and Partitioning ......................................................................................
View Constraints ..........................................................................................................................

8

7-6
7-6
7-7
7-7

Basic Materialized Views
Overview of Data Warehousing with Materialized Views.........................................................
Materialized Views for Data Warehouses ................................................................................
Materialized Views for Distributed Computing......................................................................
Materialized Views for Mobile Computing..............................................................................

The Need for Materialized Views ..............................................................................................
Components of Summary Management ...................................................................................
Data Warehousing Terminology ................................................................................................
Materialized View Schema Design ............................................................................................
Schemas and Dimension Tables ..........................................................................................
Materialized View Schema Design Guidelines.................................................................
Loading Data into Data Warehouses.......................................................................................
Overview of Materialized View Management Tasks............................................................
Types of Materialized Views ..........................................................................................................
Materialized Views with Aggregates ......................................................................................
Requirements for Using Materialized Views with Aggregates....................................
Materialized Views Containing Only Joins ............................................................................
Materialized Join Views FROM Clause Considerations................................................
Nested Materialized Views .......................................................................................................
Why Use Nested Materialized Views?.............................................................................
Nesting Materialized Views with Joins and Aggregates...............................................
Nested Materialized View Usage Guidelines .................................................................
Restrictions When Using Nested Materialized Views ...................................................
Creating Materialized Views..........................................................................................................
Creating Materialized Views with Column Alias Lists ........................................................
Naming Materialized Views .....................................................................................................
Storage And Table Compression..............................................................................................
Build Methods.............................................................................................................................
Enabling Query Rewrite ............................................................................................................
Query Rewrite Restrictions .......................................................................................................

8-2
8-2
8-3
8-3

8-3
8-5
8-7
8-8
8-8
8-9
8-10
8-11
8-12
8-12
8-15
8-15
8-16
8-17
8-17
8-19
8-19
8-20
8-20
8-21
8-22
8-22
8-23
8-24
8-24

vii


Materialized View Restrictions..........................................................................................

General Query Rewrite Restrictions .................................................................................
Refresh Options...........................................................................................................................
General Restrictions on Fast Refresh ................................................................................
Restrictions on Fast Refresh on Materialized Views with Joins Only .........................
Restrictions on Fast Refresh on Materialized Views with Aggregates........................
Restrictions on Fast Refresh on Materialized Views with UNION ALL.....................
Achieving Refresh Goals ....................................................................................................
Refreshing Nested Materialized Views ............................................................................
ORDER BY Clause ......................................................................................................................
Materialized View Logs .............................................................................................................
Using the FORCE Option with Materialized View Logs...............................................
Using Oracle Enterprise Manager ............................................................................................
Using Materialized Views with NLS Parameters ..................................................................
Adding Comments to Materialized Views .............................................................................
Registering Existing Materialized Views.....................................................................................
Choosing Indexes for Materialized Views...................................................................................
Dropping Materialized Views........................................................................................................
Analyzing Materialized View Capabilities .................................................................................
Using the DBMS_MVIEW.EXPLAIN_MVIEW Procedure ...................................................
DBMS_MVIEW.EXPLAIN_MVIEW Declarations..........................................................
Using MV_CAPABILITIES_TABLE..................................................................................
MV_CAPABILITIES_TABLE.CAPABILITY_NAME Details ...............................................
MV_CAPABILITIES_TABLE Column Details........................................................................

9

Advanced Materialized Views
Partitioning and Materialized Views ..............................................................................................
Partition Change Tracking ..........................................................................................................
Partition Key...........................................................................................................................

Join Dependent Expression ..................................................................................................
Partition Marker.....................................................................................................................
Partial Rewrite........................................................................................................................
Partitioning a Materialized View ...............................................................................................
Partitioning a Prebuilt Table .......................................................................................................
Benefits of Partitioning a Materialized View.....................................................................

viii

8-24
8-25
8-25
8-27
8-27
8-27
8-29
8-30
8-30
8-31
8-31
8-33
8-33
8-33
8-33
8-34
8-36
8-37
8-37
8-37
8-38

8-38
8-40
8-42

9-2
9-2
9-3
9-4
9-5
9-6
9-7
9-7
9-8


Rolling Materialized Views.........................................................................................................
Materialized Views in OLAP Environments.................................................................................
OLAP Cubes ..................................................................................................................................
Partitioning Materialized Views for OLAP ............................................................................
Compressing Materialized Views for OLAP..........................................................................
Materialized Views with Set Operators ..................................................................................
Examples of Materialized Views Using UNION ALL ...................................................
Materialized Views and Models ....................................................................................................
Invalidating Materialized Views ...................................................................................................
Security Issues with Materialized Views.....................................................................................
Querying Materialized Views with Virtual Private Database .............................................
Using Query Rewrite with Virtual Private Database.....................................................
Restrictions with Materialized Views and Virtual Private Database ..........................
Altering Materialized Views ..........................................................................................................


10

Dimensions
What are Dimensions? .....................................................................................................................
Creating Dimensions .......................................................................................................................
Dropping and Creating Attributes with Columns ................................................................
Multiple Hierarchies ..................................................................................................................
Using Normalized Dimension Tables ...................................................................................
Viewing Dimensions......................................................................................................................
Using Oracle Enterprise Manager..........................................................................................
Using the DESCRIBE_DIMENSION Procedure...................................................................
Using Dimensions with Constraints...........................................................................................
Validating Dimensions ..................................................................................................................
Altering Dimensions......................................................................................................................
Deleting Dimensions .....................................................................................................................

Part IV
11

9-9
9-9
9-9
9-10
9-11
9-11
9-11
9-13
9-14
9-14
9-15

9-16
9-16
9-17

10-2
10-4
10-8
10-9
10-10
10-11
10-11
10-11
10-12
10-12
10-14
10-14

Managing the Data Warehouse Environment

Overview of Extraction, Transformation, and Loading
Overview of ETL in Data Warehouses.......................................................................................... 11-2
ETL Tools for Data Warehouses ..................................................................................................... 11-3

ix


Daily Operations in Data Warehouses .................................................................................... 11-3
Evolution of the Data Warehouse ............................................................................................ 11-4

12


Extraction in Data Warehouses
Overview of Extraction in Data Warehouses ............................................................................... 12-2
Introduction to Extraction Methods in Data Warehouses......................................................... 12-2
Logical Extraction Methods....................................................................................................... 12-3
Full Extraction ...................................................................................................................... 12-3
Incremental Extraction........................................................................................................ 12-3
Physical Extraction Methods..................................................................................................... 12-4
Online Extraction ................................................................................................................. 12-4
Offline Extraction................................................................................................................. 12-4
Change Data Capture................................................................................................................. 12-5
Timestamps .......................................................................................................................... 12-6
Partitioning ........................................................................................................................... 12-6
Triggers ................................................................................................................................. 12-6
Data Warehousing Extraction Examples....................................................................................... 12-7
Extraction Using Data Files ....................................................................................................... 12-7
Extracting into Flat Files Using SQL*Plus........................................................................ 12-8
Extracting into Flat Files Using OCI or Pro*C Programs............................................... 12-9
Exporting into Export Files Using the Export Utility................................................... 12-10
Extracting into Export Files Using External Tables ...................................................... 12-10
Extraction Through Distributed Operations......................................................................... 12-11

13

Transportation in Data Warehouses
Overview of Transportation in Data Warehouses ......................................................................
Introduction to Transportation Mechanisms in Data Warehouses .........................................
Transportation Using Flat Files ................................................................................................
Transportation Through Distributed Operations ..................................................................
Transportation Using Transportable Tablespaces .................................................................

Transportable Tablespaces Example.................................................................................
Other Uses of Transportable Tablespaces........................................................................

x

13-2
13-2
13-2
13-2
13-3
13-3
13-6


14

Loading and Transformation
Overview of Loading and Transformation in Data Warehouses .............................................
Transformation Flow..................................................................................................................
Multistage Data Transformation.......................................................................................
Pipelined Data Transformation .........................................................................................
Loading Mechanisms .......................................................................................................................
Loading a Data Warehouse with SQL*Loader .......................................................................
Loading a Data Warehouse with External Tables..................................................................
Loading a Data Warehouse with OCI and Direct-Path APIs...............................................
Loading a Data Warehouse with Export/Import ..................................................................
Transformation Mechanisms ..........................................................................................................
Transformation Using SQL .......................................................................................................
CREATE TABLE ... AS SELECT And INSERT /*+APPEND*/ AS SELECT..............
Transformation Using UPDATE .......................................................................................

Transformation Using MERGE .........................................................................................
Transformation Using Multitable INSERT ....................................................................
Transformation Using PL/SQL ..............................................................................................
Transformation Using Table Functions.................................................................................
What is a Table Function? ................................................................................................
Loading and Transformation Scenarios......................................................................................
Key Lookup Scenario ...............................................................................................................
Exception Handling Scenario .................................................................................................
Pivoting Scenarios ....................................................................................................................

15

14-2
14-2
14-2
14-3
14-4
14-5
14-5
14-7
14-7
14-8
14-8
14-8
14-9
14-9
14-10
14-12
14-13
14-13

14-21
14-21
14-22
14-23

Maintaining the Data Warehouse
Using Partitioning to Improve Data Warehouse Refresh .........................................................
Refresh Scenarios ........................................................................................................................
Scenarios for Using Partitioning for Refreshing Data Warehouses ....................................
Refresh Scenario 1 ...............................................................................................................
Refresh Scenario 2 ...............................................................................................................
Optimizing DML Operations During Refresh ...........................................................................
Implementing an Efficient MERGE Operation ......................................................................
Maintaining Referential Integrity...........................................................................................
Purging Data .............................................................................................................................
Refreshing Materialized Views ...................................................................................................

15-2
15-5
15-7
15-7
15-8
15-8
15-8
15-12
15-12
15-14

xi



Complete Refresh......................................................................................................................
Fast Refresh................................................................................................................................
Partition Change Tracking (PCT) Refresh.............................................................................
ON COMMIT Refresh ..............................................................................................................
Manual Refresh Using the DBMS_MVIEW Package...........................................................
Refresh Specific Materialized Views with REFRESH..........................................................
Refresh All Materialized Views with REFRESH_ALL_MVIEWS .....................................
Refresh Dependent Materialized Views with REFRESH_DEPENDENT.........................
Using Job Queues for Refresh .................................................................................................
When Fast Refresh is Possible.................................................................................................
Recommended Initialization Parameters for Parallelism ...................................................
Monitoring a Refresh................................................................................................................
Checking the Status of a Materialized View.........................................................................
Scheduling Refresh ...................................................................................................................
Tips for Refreshing Materialized Views with Aggregates..................................................
Tips for Refreshing Materialized Views Without Aggregates ...........................................
Tips for Refreshing Nested Materialized Views ..................................................................
Tips for Fast Refresh with UNION ALL ...............................................................................
Tips After Refreshing Materialized Views............................................................................
Using Materialized Views with Partitioned Tables .................................................................
Fast Refresh with Partition Change Tracking.......................................................................
PCT Fast Refresh Scenario 1.............................................................................................
PCT Fast Refresh Scenario 2.............................................................................................
PCT Fast Refresh Scenario 3.............................................................................................
Fast Refresh with CONSIDER FRESH...................................................................................

16

15-15

15-15
15-15
15-16
15-16
15-17
15-18
15-19
15-20
15-21
15-21
15-21
15-22
15-22
15-23
15-26
15-27
15-28
15-28
15-29
15-29
15-29
15-31
15-32
15-33

Change Data Capture
Overview of Change Data Capture ............................................................................................... 16-2
Capturing Change Data Without Change Data Capture...................................................... 16-2
Capturing Change Data with Change Data Capture ............................................................ 16-4
Publish and Subscribe Model.................................................................................................... 16-5

Publisher ............................................................................................................................... 16-6
Subscribers............................................................................................................................ 16-7
Change Sources and Modes of Data Capture.............................................................................. 16-9
Synchronous .............................................................................................................................. 16-10

xii


Asynchronous ...........................................................................................................................
HotLog ................................................................................................................................
AutoLog ..............................................................................................................................
Change Sets......................................................................................................................................
Valid Combinations of Change Sources and Change Sets .................................................
Change Tables..................................................................................................................................
Getting Information About the Change Data Capture Environment ..................................
Preparing to Publish Change Data..............................................................................................
Creating a User to Serve As a Publisher ...............................................................................
Granting Privileges and Roles to the Publisher ............................................................
Creating a Default Tablespace for the Publisher ..........................................................
Password Files and Setting the REMOTE_LOGIN_PASSWORDFILE Parameter .
Determining the Mode in Which to Capture Data ..............................................................
Setting Initialization Parameters for Change Data Capture Publishing...........................
Initialization Parameters for Synchronous Publishing ................................................
Initialization Parameters for Asynchronous HotLog Publishing...............................
Initialization Parameters for Asynchronous AutoLog Publishing ............................
Determining the Current Setting of an Initialization Parameter................................
Retaining Initialization Parameter Values When a Database Is Restarted ...............
Adjusting Initialization Parameter Values When Oracle Streams Values Change .
Publishing Change Data ...............................................................................................................
Performing Synchronous Publishing.....................................................................................

Performing Asynchronous HotLog Publishing ...................................................................
Performing Asynchronous AutoLog Publishing .................................................................
Subscribing to Change Data.........................................................................................................
Considerations for Asynchronous Change Data Capture ......................................................
Asynchronous Change Data Capture and Redo Log Files.................................................
Asynchronous Change Data Capture and Supplemental Logging...................................
Datatypes and Table Structures Supported for Asynchronous Change Data Capture .
Managing Published Data ............................................................................................................
Managing Asynchronous Change Sets..................................................................................
Creating Asynchronous Change Sets with Starting and Ending Dates ....................
Enabling and Disabling Asynchronous Change Sets...................................................
Stopping Capture on DDL for Asynchronous Change Sets........................................
Recovering from Errors Returned on Asynchronous Change Sets............................

16-11
16-12
16-13
16-14
16-15
16-16
16-16
16-18
16-18
16-19
16-19
16-19
16-20
16-21
16-21
16-21

16-22
16-25
16-25
16-25
16-27
16-27
16-30
16-35
16-42
16-47
16-48
16-50
16-51
16-52
16-52
16-52
16-53
16-54
16-55

xiii


Managing Change Tables ........................................................................................................
Creating Change Tables....................................................................................................
Understanding Change Table Control Columns ..........................................................
Understanding TARGET_COLMAP$ and SOURCE_COLMAP$ Values ................
Controlling Subscriber Access to Change Tables .........................................................
Purging Change Tables of Unneeded Data ...................................................................
Dropping Change Tables..................................................................................................

Considerations for Exporting and Importing Change Data Capture Objects .................
Impact on Subscriptions When the Publisher Makes Changes .........................................
Implementation and System Configuration ..............................................................................
Synchronous Change Data Capture Restriction on Direct-Path INSERT.........................

17

16-58
16-59
16-60
16-62
16-64
16-65
16-67
16-67
16-70
16-71
16-72

SQLAccess Advisor
Overview of the SQLAccess Advisor in the DBMS_ADVISOR Package ............................. 17-2
Overview of Using the SQLAccess Advisor ........................................................................... 17-4
SQLAccess Advisor Repository......................................................................................... 17-7
Using the SQLAccess Advisor........................................................................................................ 17-7
SQLAccess Advisor Flowchart ................................................................................................. 17-8
SQLAccess Advisor Privileges.................................................................................................. 17-9
Creating Tasks........................................................................................................................... 17-10
SQLAccess Advisor Templates............................................................................................... 17-10
Creating Templates................................................................................................................... 17-11
Workload Objects...................................................................................................................... 17-12

Managing Workloads............................................................................................................... 17-12
Linking a Task and a Workload.............................................................................................. 17-13
Defining the Contents of a Workload .................................................................................... 17-14
SQL Tuning Set .................................................................................................................. 17-14
Loading a User-Defined Workload................................................................................. 17-15
Loading a SQL Cache Workload ..................................................................................... 17-16
Using a Hypothetical Workload...................................................................................... 17-17
Using a Summary Advisor 9i Workload........................................................................ 17-18
SQLAccess Advisor Workload Parameters ................................................................... 17-19
SQL Workload Journal............................................................................................................. 17-20
Adding SQL Statements to a Workload ................................................................................ 17-20
Deleting SQL Statements from a Workload.......................................................................... 17-21

xiv


Changing SQL Statements in a Workload ............................................................................
Maintaining Workloads...........................................................................................................
Setting Workload Attributes............................................................................................
Resetting Workloads .........................................................................................................
Removing a Link Between a Workload and a Task .....................................................
Removing Workloads ..............................................................................................................
Recommendation Options.......................................................................................................
Generating Recommendations ...............................................................................................
EXECUTE_TASK Procedure............................................................................................
Viewing the Recommendations..............................................................................................
Access Advisor Journal............................................................................................................
Stopping the Recommendation Process................................................................................
Canceling Tasks .................................................................................................................
Marking Recommendations....................................................................................................

Modifying Recommendations ................................................................................................
Generating SQL Scripts............................................................................................................
When Recommendations are No Longer Required.............................................................
Performing a Quick Tune ........................................................................................................
Managing Tasks ........................................................................................................................
Updating Task Attributes.................................................................................................
Deleting Tasks....................................................................................................................
Setting DAYS_TO_EXPIRE ..............................................................................................
Using SQLAccess Advisor Constants....................................................................................
Examples of Using the SQLAccess Advisor .........................................................................
Recommendations From a User-Defined Workload....................................................
Generate Recommendations Using a Task Template ..................................................
Filter a Workload from the SQL Cache ..........................................................................
Evaluate Current Usage of Indexes and Materialized Views .....................................
Tuning Materialized Views for Fast Refresh and Query Rewrite.........................................
DBMS_ADVISOR.TUNE_MVIEW Procedure .....................................................................
TUNE_MVIEW Syntax and Operations.........................................................................
Accessing TUNE_MVIEW Output Results....................................................................
USER_TUNE_MVIEW and DBA_TUNE_MVIEW Views...........................................
Script Generation DBMS_ADVISOR Function and Procedure ..................................
Fast Refreshable with Optimized Sub-Materialized View ..........................................

17-22
17-22
17-23
17-23
17-23
17-24
17-24
17-25

17-26
17-26
17-32
17-32
17-32
17-33
17-33
17-34
17-36
17-36
17-37
17-37
17-38
17-38
17-38
17-39
17-39
17-42
17-44
17-46
17-47
17-48
17-48
17-50
17-50
17-50
17-56

xv



Volume 2
Part V
18

Data Warehouse Performance

Query Rewrite
Overview of Query Rewrite............................................................................................................ 18-2
Cost-Based Rewrite..................................................................................................................... 18-3
When Does Oracle Rewrite a Query? ...................................................................................... 18-4
Enabling Query Rewrite.................................................................................................................. 18-5
Initialization Parameters for Query Rewrite .......................................................................... 18-5
Controlling Query Rewrite........................................................................................................ 18-6
Accuracy of Query Rewrite ....................................................................................................... 18-7
Query Rewrite Hints ........................................................................................................... 18-8
Privileges for Enabling Query Rewrite.................................................................................... 18-9
Sample Schema and Materialized Views ................................................................................ 18-9
How Oracle Rewrites Queries ...................................................................................................... 18-11
Text Match Rewrite Methods.................................................................................................. 18-11
Text Match Capabilities .................................................................................................... 18-13
General Query Rewrite Methods............................................................................................ 18-13
When are Constraints and Dimensions Needed? ......................................................... 18-13
Join Back.............................................................................................................................. 18-14
Rollup Using a Dimension ............................................................................................... 18-16
Compute Aggregates ........................................................................................................ 18-17
Filtering the Data ............................................................................................................... 18-18
Dropping Selections in the Rewritten Query ................................................................ 18-24
Handling of HAVING Clause in Query Rewrite.......................................................... 18-25
Handling Expressions in Query Rewrite ....................................................................... 18-25

Handling IN-Lists in Query Rewrite .............................................................................. 18-26
Checks Made by Query Rewrite............................................................................................. 18-28
Join Compatibility Check ................................................................................................. 18-28
Data Sufficiency Check ..................................................................................................... 18-33
Grouping Compatibility Check ....................................................................................... 18-34
Aggregate Computability Check..................................................................................... 18-34
Other Cases for Query Rewrite............................................................................................... 18-34
Query Rewrite Using Partially Stale Materialized Views ........................................... 18-35

xvi


Query Rewrite Using Nested Materialized Views .......................................................
Query Rewrite When Using GROUP BY Extensions ...................................................
Hint for Queries with Extended GROUP BY ................................................................
Query Rewrite with Inline Views ...................................................................................
Query Rewrite with Selfjoins...........................................................................................
Query Rewrite and View Constraints ............................................................................
Query Rewrite and Expression Matching......................................................................
Date Folding Rewrite ........................................................................................................
Partition Change Tracking (PCT) Rewrite ............................................................................
PCT Rewrite Based on LIST Partitioned Tables............................................................
PCT and PMARKER .........................................................................................................
PCT Rewrite with Materialized Views Based on Range-List Partitioned Tables ....
PCT Rewrite Using Rowid as Pmarker ..........................................................................
Query Rewrite and Bind Variables ........................................................................................
Query Rewrite Using Set Operator Materialized Views.....................................................
UNION ALL Marker.........................................................................................................
Did Query Rewrite Occur?............................................................................................................
Explain Plan...............................................................................................................................

DBMS_MVIEW.EXPLAIN_REWRITE Procedure ...............................................................
DBMS_MVIEW.EXPLAIN_REWRITE Syntax ..............................................................
Using REWRITE_TABLE .................................................................................................
Using a Varray ...................................................................................................................
EXPLAIN_REWRITE Benefit Statistics ..........................................................................
Support for Query Text Larger than 32KB in EXPLAIN_REWRITE .........................
Design Considerations for Improving Query Rewrite Capabilities ....................................
Query Rewrite Considerations: Constraints.........................................................................
Query Rewrite Considerations: Dimensions ........................................................................
Query Rewrite Considerations: Outer Joins .........................................................................
Query Rewrite Considerations: Text Match .........................................................................
Query Rewrite Considerations: Aggregates .........................................................................
Query Rewrite Considerations: Grouping Conditions .......................................................
Query Rewrite Considerations: Expression Matching........................................................
Query Rewrite Considerations: Date Folding ......................................................................
Query Rewrite Considerations: Statistics..............................................................................
Advanced Rewrite Using Equivalences .....................................................................................

18-38
18-39
18-44
18-44
18-45
18-46
18-49
18-49
18-52
18-52
18-55
18-57

18-59
18-61
18-62
18-64
18-65
18-65
18-66
18-66
18-67
18-69
18-71
18-71
18-72
18-72
18-73
18-73
18-73
18-73
18-74
18-74
18-74
18-74
18-75

xvii


19

Schema Modeling Techniques

Schemas in Data Warehouses ......................................................................................................... 19-2
Third Normal Form .......................................................................................................................... 19-2
Optimizing Third Normal Form Queries................................................................................ 19-3
Star Schemas ...................................................................................................................................... 19-3
Snowflake Schemas .................................................................................................................... 19-5
Optimizing Star Queries ................................................................................................................. 19-5
Tuning Star Queries.................................................................................................................... 19-6
Using Star Transformation ........................................................................................................ 19-6
Star Transformation with a Bitmap Index ....................................................................... 19-6
Execution Plan for a Star Transformation with a Bitmap Index................................... 19-9
Star Transformation with a Bitmap Join Index ............................................................. 19-10
Execution Plan for a Star Transformation with a Bitmap Join Index......................... 19-10
How Oracle Chooses to Use Star Transformation ........................................................ 19-11
Star Transformation Restrictions..................................................................................... 19-11

20

SQL for Aggregation in Data Warehouses
Overview of SQL for Aggregation in Data Warehouses ........................................................... 20-2
Analyzing Across Multiple Dimensions ................................................................................. 20-2
Optimized Performance............................................................................................................. 20-4
An Aggregate Scenario .............................................................................................................. 20-4
Interpreting NULLs in Examples ............................................................................................. 20-6
ROLLUP Extension to GROUP BY................................................................................................ 20-6
When to Use ROLLUP ............................................................................................................... 20-6
ROLLUP Syntax .......................................................................................................................... 20-6
Partial Rollup............................................................................................................................... 20-8
CUBE Extension to GROUP BY ..................................................................................................... 20-9
When to Use CUBE..................................................................................................................... 20-9
CUBE Syntax ............................................................................................................................. 20-10

Partial CUBE.............................................................................................................................. 20-11
Calculating Subtotals Without CUBE .................................................................................... 20-12
GROUPING Functions .................................................................................................................. 20-12
GROUPING Function .............................................................................................................. 20-13
When to Use GROUPING ....................................................................................................... 20-15
GROUPING_ID Function ........................................................................................................ 20-15

xviii


GROUP_ID Function................................................................................................................
GROUPING SETS Expression .....................................................................................................
GROUPING SETS Syntax........................................................................................................
Composite Columns.......................................................................................................................
Concatenated Groupings...............................................................................................................
Concatenated Groupings and Hierarchical Data Cubes.....................................................
Considerations when Using Aggregation..................................................................................
Hierarchy Handling in ROLLUP and CUBE........................................................................
Column Capacity in ROLLUP and CUBE.............................................................................
HAVING Clause Used with GROUP BY Extensions ..........................................................
ORDER BY Clause Used with GROUP BY Extensions .......................................................
Using Other Aggregate Functions with ROLLUP and CUBE ...........................................
Computation Using the WITH Clause .......................................................................................
Working with Hierarchical Cubes in SQL .................................................................................
Specifying Hierarchical Cubes in SQL ..................................................................................
Querying Hierarchical Cubes in SQL ....................................................................................
SQL for Creating Materialized Views to Store Hierarchical Cubes ...........................
Examples of Hierarchical Cube Materialized Views....................................................

21


20-16
20-17
20-19
20-20
20-22
20-24
20-26
20-26
20-27
20-27
20-28
20-28
20-28
20-29
20-29
20-30
20-31
20-32

SQL for Analysis and Reporting
Overview of SQL for Analysis and Reporting............................................................................
Ranking Functions............................................................................................................................
RANK and DENSE_RANK Functions ....................................................................................
Ranking Order .....................................................................................................................
Ranking on Multiple Expressions .....................................................................................
RANK and DENSE_RANK Difference ............................................................................
Per Group Ranking .............................................................................................................
Per Cube and Rollup Group Ranking ............................................................................
Treatment of NULLs .........................................................................................................

Bottom N Ranking....................................................................................................................
CUME_DIST Function .............................................................................................................
PERCENT_RANK Function....................................................................................................
NTILE Function ........................................................................................................................
ROW_NUMBER Function.......................................................................................................
Windowing Aggregate Functions ................................................................................................

21-2
21-5
21-5
21-6
21-7
21-8
21-8
21-10
21-10
21-12
21-12
21-13
21-13
21-15
21-15

xix


Treatment of NULLs as Input to Window Functions..........................................................
Windowing Functions with Logical Offset ...........................................................................
Centered Aggregate Function.................................................................................................
Windowing Aggregate Functions in the Presence of Duplicates ......................................

Varying Window Size for Each Row .....................................................................................
Windowing Aggregate Functions with Physical Offsets....................................................
FIRST_VALUE and LAST_VALUE Functions .....................................................................
Reporting Aggregate Functions ...................................................................................................
RATIO_TO_REPORT Function ..............................................................................................
LAG/LEAD Functions ....................................................................................................................
LAG/LEAD Syntax ..................................................................................................................
FIRST/LAST Functions..................................................................................................................
FIRST/LAST Syntax .................................................................................................................
FIRST/LAST As Regular Aggregates ....................................................................................
FIRST/LAST As Reporting Aggregates ................................................................................
Inverse Percentile Functions.........................................................................................................
Normal Aggregate Syntax .......................................................................................................
Inverse Percentile Example Basis ....................................................................................
As Reporting Aggregates .................................................................................................
Inverse Percentile Restrictions ................................................................................................
Hypothetical Rank and Distribution Functions .......................................................................
Hypothetical Rank and Distribution Syntax.........................................................................
Linear Regression Functions.........................................................................................................
REGR_COUNT Function.........................................................................................................
REGR_AVGY and REGR_AVGX Functions .........................................................................
REGR_SLOPE and REGR_INTERCEPT Functions .............................................................
REGR_R2 Function ...................................................................................................................
REGR_SXX, REGR_SYY, and REGR_SXY Functions ..........................................................
Linear Regression Statistics Examples...................................................................................
Sample Linear Regression Calculation ..................................................................................
Frequent Itemsets............................................................................................................................
Other Statistical Functions............................................................................................................
Descriptive Statistics.................................................................................................................
Hypothesis Testing - Parametric Tests ..................................................................................

Crosstab Statistics .....................................................................................................................

xx

21-16
21-16
21-18
21-19
21-20
21-21
21-21
21-22
21-24
21-25
21-25
21-26
21-26
21-26
21-27
21-28
21-28
21-28
21-30
21-31
21-32
21-32
21-33
21-34
21-34
21-34

21-35
21-35
21-35
21-35
21-36
21-37
21-37
21-37
21-38



×