Skip Headers

Oracle9i Data Warehousing Guide
Release 2 (9.2)

Part Number A96520-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

16
Summary Advisor

This chapter illustrates how to use the Summary Advisor, a tool for choosing and understanding materialized views. The chapter contains:

Overview of the Summary Advisor in the DBMS_OLAP Package

Materialized views provide high performance for complex, data-intensive queries. The Summary Advisor helps you achieve this performance benefit by choosing the proper set of materialized views for a given workload. In general, as the number of materialized views and space allocated to materialized views is increased, query performance improves. But the additional materialized views have some cost: they consume additional storage space and must be refreshed, which increases maintenance time. The Summary Advisor considers these costs and makes the most cost-effective trade-offs when recommending the creation of new materialized views and evaluating the performance of existing materialized views.

To help you select from among the many possible materialized views in your schema, Oracle provides a collection of materialized view analysis and advisory functions and procedures in the DBMS_OLAP package. Collectively, these functions are called the Summary Advisor, and they are callable from any PL/SQL program. Figure 16-1 shows how the Summary Advisor recommends materialized views from a hypothetical or user-defined workload or one obtained from the SQL cache, or Oracle Trace. You can run the Summary Advisor from Oracle Enterprise Manager or by invoking the DBMS_OLAP package. You must have Java enabled to use the Summary Advisor.

All data and results generated by the Summary Advisor is stored in a set of tables referred to as the Summary Advisor repository. These tables are owned by SYSTEM and start with MVIEW$_ADV_*. Only DBAs can access these tables directly, but other users can access the data relevant to them using a set of read-only views. These views start with MVIEW_. Thus, the table MVIEW$_ADV_WORKLOAD stores the workload of all users, but a user accesses his workload through the MVIEW_WORKLOAD view.

Figure 16-1 Materialized Views and the Summary Advisor

Text description of dwhsg085.gif follows
Text description of the illustration dwhsg085.gif


Using the Summary Advisor or the DBMS_OLAP package, you can:

All of these tasks can be performed independently of one another. However, sometimes you need to use several procedures from the DBMS_OLAP package to complete a task. For example, to recommend a set of materialized views based on a workload, you have to first load the workload and then generate the set of recommendations.

Before you can use any of these procedures, you must create a unique identifier for the data they are about to create. This number is obtained by calling the procedure CREATE_ID and the unique number is known subsequently as a run ID, workload ID or filter ID depending on the procedure it is given.

The identifier is used to store the Advisor artifacts in the repository. Each activity in the Advisor requires a unique identifier to distinguish it from other objects. For example, when you add a filter item, you associate the item with a filter ID. When you load a workload, the data gets stored using the unique workload ID. In addition, when you run RECOMMEND_MVIEW_STRATEGY or EVALUATE_MVIEW_STRATEGY, a unique ID is associated with the run.

Because the ID is just a unique number, Oracle uses the same CREATE_ID function to acquire the value. It is only when a specific operation is performed (such as a load workload) that the ID is identified as a workload ID.

You can use the Summary Advisor with or without a workload, but better results are achieved if a workload is provided. This can be supplied by:

Once the workload is loaded into the Advisor workload repository or at the time the materialized view recommendations are generated, a filter can be applied to the workload to restrict what is analyzed. This provides the ability to generate different sets of recommendations based on different workload scenarios.

These filters are created using the procedure ADD_FILTER_ITEM. You can create any number of filters, and use more than one at a time to filter a workload. See "Using Filters with the Summary Advisor" for further details.

The Summary Advisor uses four types of schema objects, some of which are defined in the user's schema and some are in the system schema:

If you want to view the results of the last materialized view recommendation, you can issue the following statement:

SELECT MVIEW_OWNER, MVIEW_NAME, RECOMMENDED_ACTION, PCT_PERFORMANCE_GAIN, 
   BENEFIT_TO_COST_RATIO
FROM SYSTEM.MVIEW_RECOMMENDATIONS
WHERE RUNID= (SELECT MAX(RUNID) FROM SYSTEM.MVIEW_RECOMMENDATIONS)
  ORDER BY RECOMMENDATION_NUMBER ASC

The advisory functions and procedures of the DBMS_OLAP package require you to gather structural statistics about fact and dimension table cardinalities, and the distinct cardinalities of every dimension level column, JOIN KEY column, and fact table key column. You do this by loading your data warehouse, then gathering either exact or estimated statistics with the DBMS_STATS package or the ANALYZE TABLE statement. Because gathering statistics is time-consuming and extreme statistical accuracy is not required, it is generally preferable to estimate statistics.

Using information from the system workload table, schema metadata and statistical information generated by the DBMS_STATS package, the Advisor engine generates summary recommendations and summary usage evaluations and stores the results in result tables.

To use the Summary Advisor with a workload, some or all of the following steps must be followed:

These steps can be repeated several times with different workloads to see the effect on the materialized views.

Using the Summary Advisor

The following sections will help you use the Advisor:

Identifier Numbers

Most of the DBMS_OLAP procedures require a unique identifier as one of their parameters. You obtain this by calling the procedure CREATE_ID, which is illustrated in the following section.

DBMS_OLAP.CREATE_ID Procedure

Table 16-1 DBMS_OLAP.CREATE_ID Procedure Parameters
Parameter Datatype Description
id
NUMBER

The unique identifier that can be used to create a filter, load a workload, or create an analysis

With a SQL utility such as SQL*Plus, do the following:

  1. Declare an output variable to receive the new identifier.
    VARIABLE MY_ID NUMBER;
    
    
  2. Call the CREATE_ID function to generate a new identifier.
    EXECUTE DBMS_OLAP.CREATE_ID(:MY_ID);
    

Workload Management

The Advisor performs best when a workload based on usage is available. The Advisor Workload Repository is capable of storing multiple workloads, so that the different uses of a real-world data warehousing environment can be viewed over a long period of time and across the life cycle of database instance startup and shutdown.

To facilitate wider use of the Summary Advisor, three types of workload are supported:

When the workload is loaded using the appropriate load_workload procedure, it is stored in a new workload repository in the SYSTEM schema called MVIEW_WORKLOAD whose format is shown in Table 16-2. A specific workload can be removed by calling the PURGE_WORKLOAD routine and passing it a valid workload ID. To remove all workloads for the current user, call PURGE_WORKLOAD and pass the constant value DBMS_OLAP.WORKLOAD_ALL.

Table 16-2 MVIEW_WORKLOAD Table 
Column Datatype Description

APPLICATION

VARCHAR2(30)

Optional application name for the query

CARDINALITY

NUMBER

Total cardinality of all of tables in query

WORKLOADID

NUMBER

Workload id identifying a unique sampling

FREQUENCY

NUMBER

Number of times query executed

IMPORT_TIME

DATE

Date at which item was collected

LASTUSE

DATE

Last date of execution

OWNER

VARCHAR2(30)

User who last executed query

PRIORITY

NUMBER

User-supplied ranking of query

QUERY

LONG

Query text

QUERYID

NUMBER

Id number identifying a unique query

RESPONSETIME

NUMBER

Execution time in seconds

RESULTSIZE

NUMBER

Total bytes selected by the query

Once the workload has been collected using the appropriate LOAD_WORKLOAD routine, there is also a filter mechanism that may be applied, this lets you specify the portion of workload that is to be loaded into the repository. You can also use the same filter mechanism to restrict workload-based summary recommendation and evaluation to a subset of the queries contained in the workload repository. Once the workload has been loaded, the Summary Advisor is run by calling the procedure RECOMMEND_MVIEW_STRATEGY. A major benefit of this approach is that it is easy to model different workloads by simply modifying the frequency column, removing some SQL queries, or adding new queries.

Summary Advisor can retrieve workload information from the SQL cache as well as Oracle Trace. If the collected data was retrieved from a server with the instance parameter cursor_sharing set to SIMILAR or FORCE, then user queries with embedded literal values will be converted to a statement that contains system-generated bind variables.


Note:

Oracle Trace will be deprecated in a future release.


In Oracle9i, it is not possible to retrieve the bind-variable data in order to reconstruct the statement in the form originally submitted by the user. This will, in turn, cause Summary Advisor to not consider the query for rewrite and potentially miss a critical statement in the user's workload. As a work-around, if the Advisor will be used to recommend materialized views, then the server should set the instance parameter CURSOR_SHARING to EXACT.

Loading a User-Defined Workload

A user-defined workload is loaded using the procedure LOAD_WORKLOAD_USER. The workload_id is obtained by calling the procedure CREATE_ID. The value of the flags parameter determines whether the workload is considered to be new, should be used to overwrite an existing workload, or should be appended to an existing workload. The optional filter_id can be supplied to specify the filter that is to be used against this workload. Where the filter would have been defined using the ADD_FILTER_ITEM procedure.

DBMS_OLAP.LOAD_WORKLOAD_USER Procedure

Table 16-3 DBMS_OLAP.LOAD_WORKLOAD_USER Procedure Parameters 
Parameter Datatype Description
workload_id
NUMBER

The required workload id that was returned by the create_id call

flags
NUMBER

Can take one of the following values:

DBMS_OLAP.WORKLOAD_OVERWRITE

The load routine will explicitly remove any existing queries from the workload that are owned by the specified collection ID

DBMS_OLAP.WORKLOAD_APPEND

The load routine preserves any existing queries in the workload. Any queries collected by the load operation will be appended to the end of the specified workload

DBMS_OLAP.WORKLOAD_NEW

The load routine assumes there are no existing queries in the workload. If it finds an existing workload element, the call will fail with an error

Note: the flags have the same behavior irrespective of the LOAD_WORKLOAD operation

filter_id
NUMBER

Specify filter for the workload to be loaded

owner_name
VARCHAR2

The schema that contains the user supplied table or view

table_name
VARCHAR2

The table or view name containing valid workload data

The actual workload is defined in a separate table and the two parameters owner_name and table_name describe where it is stored. There is no restriction on which schema the workload resides in, the name for the table, or how many of these user-defined tables exist. The only restriction is that the format of the user table must correspond to the USER_WORKLOAD table, as described in Table 16-4:

Table 16-4 USER_WORKLOAD 
Column Datatype Optional/
Required
Description

QUERY

Can be any VARCHAR or LONG type.

All character types are supported

Required

SQL statement

OWNER

VARCHAR2(30)

Required

User who last executed query

APPLICATION

VARCHAR2(30)

Optional

Application name for the query

FREQUENCY

NUMBER

Optional

Number of times query executed

LASTUSE

DATE

Optional

Last date of execution

PRIORITY

NUMBER

Optional

User-supplied ranking of query

RESPONSETIME

NUMBER

Optional

Execution time in seconds

RESULTSIZE

NUMBER

Optional

Total bytes selected by the query

SQL_ADDR

NUMBER

Optional

Cache address

SQL_HASH

NUMBER

Optional

Cache hash value

The following is an example of loading a user workload.

  1. Declare an output variable to receive the new identifier.
    VARIABLE MY_ID NUMBER;
    
    
  2. Call the CREATE_ID function to generate a new identifier.
    EXECUTE DBMS_OLAP.CREATE_ID(:MY_ID);
    
    
  3. Insert into the MY_WORKLOAD tables the queries you want advice on.
    INSERT INTO advisor_user_workload VALUES
    (
     'SELECT SUM(s.quantity_sold)
      FROM sales s, products p
      WHERE s.prod_id = p.prod_id AND p.prod_category = ''Boys''
      GROUP BY p.prod_category', 'SH', 'app1', 10, NULL, 5, NULL, NULL)
    
    
  4. Load the workload from a target table or view.
    EXECUTE DBMS_OLAP.LOAD_WORKLOAD_USER(:MY_ID, DBMS_OLAP.WORKLOAD_NEW,
       DBMS_OLAP.FILTER_NONE, 'SH', 'MY_WORKLOAD');
    

Loading a Trace Workload

Alternatively, you can collect a Trace workload from Oracle Enterprise Manager to gather dynamic information about your query workload, which can be used by an advisory function. If Oracle Trace is available, consider using it to collect materialized view usage. Doing so enables you to see which materialized views are in use. It also lets the Advisor detect any unusual query requests from users that would result in recommending some different materialized views.

A workload collected by Oracle Trace is loaded using the procedure LOAD_WORKLOAD_TRACE. You obtain workload_id by calling the procedure CREATE_ID. The value of the flags parameter will determine whether the workload is considered new, should be used to overwrite an existing workload or should be appended to an existing workload. The optional filter ID can be supplied to specify the filter that is to be used against this workload. In addition, you can specify an application name to describe this workload and give every query a default priority. The application name is simply a tag that enables you to classify the workload query. The name can later be used to filter the workload during a RECOMMEND_MVIEW_STRATEGY or EVALUATE_MVIEW_STRATEGY operation.

The priority is an important piece of information. It tells the Advisor how important the query is to the business. When recommendations are formed, the priority will determine its value and will cause the Advisor to make decisions that favor higher ranking queries.

If the owner_name parameter is not defined, then the procedure will expect to find the formatted trace tables in the schema for the current user.

DBMS_OLAP.LOAD_WORKLOAD_TRACE Procedure

Table 16-5 DBMS_OLAP.LOAD_WORKLOAD_TRACE Procedure Parameters 
Parameter Datatype Description
workload_id
NUMBER

The required id that was returned by the CREATE_ID call

flags
NUMBER

Can take one of the following values:

DBMS_OLAP.WORKLOAD_OVERWRITE

The load routine will explicitly remove any existing queries from the workload that are owned by the specified collection ID

DBMS_OLAP.WORKLOAD_APPEND

The load routine preserves any existing queries in the workload. Any queries collected by the load operation will be appended to the end of the specified workload

DBMS_OLAP.WORKLOAD_NEW

The load routine assumes there are no existing queries in the workload. If it finds an existing workload element, the call will fail with an error

Note: the flags have the same behavior irrespective of the LOAD_WORKLOAD operation

filter_id
NUMBER

Specify filter for the workload to be loaded

application
VARCHAR2

The default business application name. This value will be used for a query if one is not found in the target workload

priority
NUMBER

The default business priority to be assigned to every query in the target workload

owner_name
VARCHAR2

The schema that contains the Oracle Trace data. If omitted, the current user will be used

Oracle Trace collects two types of data. One is a duration event which causes a data item to be collected twice: once at the start of the operation and once at the end of the operation. The duration of the data item is the difference between the start and end of the operation. For example, execution time is collected as a duration event. It first collects the clock time when the operation starts. Then it collects the clock time when the operation ends. Execution time is calculated by subtracting the start time from the end time.

A point event is a static data item that doesn't change over time. For example, an owner name is a static data item that would be the same at the start and the end of an operation.

To collect, analyze and load the summary event set, you must do the following:

  1. Set six initialization parameters to collect data using Oracle Trace. Enabling these parameters incurs some additional overhead at database connection, but is otherwise transparent.
    • ORACLE_TRACE_COLLECTION_NAME = oraclesm or oraclee

      ORACLEE is the Oracle Expert collection which contains Summary Advisor data and additional data that is only used by Oracle Expert.

      ORACLESM is the Summary Advisor collection that contains only Summary Advisor data and is the preferred collection type.

    • ORACLE_TRACE_COLLECTION_PATH = location of collection files
    • ORACLE_TRACE_COLLECTION_SIZE = 0
    • ORACLE_TRACE_ENABLE = TRUE
    • ORACLE_TRACE_FACILITY_NAME = oraclesm or oralcee
    • ORACLE_TRACE_FACILITY_PATH = location of trace facility files

      See Also:

      Oracle9i Database Performance Tuning Guide and Reference for further information regarding these parameters

  1. Run the Oracle Trace Manager, specify a collection name, and select the SUMMARY_EVENT set. Oracle Trace Manager reads information from the associated configuration file and registers events to be logged with Oracle. While collection is enabled, the workload information defined in the event set gets written to a flat log file.
  2. When collection is complete, Oracle Trace automatically formats the Oracle Trace log file into a set of relations, which have the predefined synonyms beginning with V_192216243_. Alternatively, the collection file, which usually has an extension of .CDF, can be formatted manually using the otrcfmt utility, as shown in this example:
    otrcfmt   collection_name.cdf   user/password@database
    
    

The trace data can be formatted in any schema. The LOAD_WORKLOAD_TRACE call lets you specify the location of the data.


Go to previous page Go to next page
Oracle
Copyright © 1996, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback