Skip Headers
Oracle® OLAP Reference
10g Release 2 (10.2)

Part Number B14350-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

Example: Manually Choose the Grouping Sets for a Cube

This example creates materialized views for the cube PRICE_CUBE in the GLOBAL schema.

This cube contains unit costs and unit prices for different products over time. The dimensions are PRODUCT, with levels for products, families of products, classes of products, and totals, and TIME with levels for months, quarters, and years.

You want to summarize product families by month and product classes by quarter.

  1. Identify a scripts directory. The directory can be specified in the UTL_FILE_DIR initialization parameter, or you can define a directory object with a statement like the following.

    CREATE OR REPLACE DIRECTORY GLOBALDIR AS '/users/global/scripts';
    GRANT ALL ON DIRECTORY GLOBALDIR TO PUBLIC;
    
    
  2. Generate the scripts for the dimension materialized views. The following statements create the scripts prodmv.sql and timemv.sql in the /users/global/scripts directory.

    exec dbms_odm.createdimmv_gs
          ('global', 'product', 'prodmv.sql', 'GLOBALDIR');
    exec dbms_odm.createdimmv_gs
          ('global', 'time', 'timemv.sql', 'GLOBALDIR');
    
    
  3. Run these scripts to create the dimension materialized views. The scripts will create one materialized view for the PRODUCT dimension and one for the TIME dimension.

  4. Create the table of dimension levels for the fact materialized view.

    exec dbms_odm.createdimlevtuple('global', 'price_cube');
    
    

    The table of levels, sys.olaptablevels, is a temporary table specific to your session. It lists all the levels in PRICE_CUBE. You can view the table as follows.

    select * from sys.olaptablevels;
    
    SCHEMA_NAME DIMENSION_NAME DIMENSION_OWNER CUBE_NAME    LEVEL_NAME SELECTED
    ----------- -------------- --------------- ----------   ---------- --------
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   YEAR            1
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   QUARTER         1
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   MONTH           1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   TOTAL_PRODUCT   1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   CLASS           1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   FAMILY          1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   ITEM            1
    
    

    All the levels are initially selected with "1" in the SELECTED column.

  5. Since you want the materialized view to include only product families by month and product classes by quarter, you can deselect all other levels. You could edit the table with a statement like the following.

    update SYS.OLAPTABLEVELS set selected = 0 
       where LEVEL_NAME in ('ITEM','TOTAL_PRODUCT', 'YEAR');
    select * from sys.olaptablevels;
    
    SCHEMA_NAME DIMENSION_NAME DIMENSION_OWNER CUBE_NAME    LEVEL_NAME SELECTED
    ----------- -------------- --------------- ----------   ---------- --------
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   YEAR            0
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   QUARTER         1
    GLOBAL      TIME           GLOBAL          PRICE_CUBE   MONTH           1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   TOTAL_PRODUCT   0
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   CLASS           1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   FAMILY          1
    GLOBAL      PRODUCT        GLOBAL          PRICE_CUBE   ITEM            0
    
    
  6. Next create the table sys.olaptableveltuples. This table, which is also a session-specific temporary table, contains all the possible combinations of the levels that you selected in the previous step. Each combination of levels, or grouping set, has an identification number. All the grouping sets are initially selected with "1" in the SELECTED column.

    exec dbms_odm.createcubeleveltuple('global','price_cube');
    select ID, SCHEMA_NAME, CUBE_NAME, DIMENSION_NAME, DIMENSION_OWNER, 
           LEVEL_NAME, SELECTED
           from sys.olaptableveltuples;
    
    ID SCHEMA_NAME CUBE_NAME   DIMENSION_NAME DIMENSION_OWNER LEVEL_NAME SELECTED
    -- ----------- ---------   -------------- --------------- ---------- --------
    1   GLOBAL     PRICE_CUBE  PRODUCT        GLOBAL          FAMILY      1
    2   GLOBAL     PRICE_CUBE  PRODUCT        GLOBAL          CLASS       1
    3   GLOBAL     PRICE_CUBE  PRODUCT        GLOBAL          FAMILY      1
    4   GLOBAL     PRICE_CUBE  PRODUCT        GLOBAL          CLASS       1
    1   GLOBAL     PRICE_CUBE  TIME           GLOBAL          MONTH       1
    2   GLOBAL     PRICE_CUBE  TIME           GLOBAL          MONTH       1
    3   GLOBAL     PRICE_CUBE  TIME           GLOBAL          QUARTER     1
    4   GLOBAL     PRICE_CUBE  TIME           GLOBAL          QUARTER     1
    
    

    There are four grouping sets numbered 1, 2, 3, and 4. Each grouping set identifies a unique combination of the levels Quarter and Month in the TIME dimension and CLASS and FAMILY in the PRODUCT dimension.

  7. Since you want the materialized view to include only product families by month and product classes by quarter, you can deselect the other level combinations. You could edit the sys.olaptableveltuples table with a statement like the following.

    update sys.olaptableveltuples set selected = 0    where ID in ('2', '3');
    
    select ID, SCHEMA_NAME, CUBE_NAME, DIMENSION_NAME, DIMENSION_OWNER, 
           LEVEL_NAME, SELECTED
           from sys.olaptableveltuples where SELECTED = '1';
    
    ID SCHEMA_NAME CUBE_NAME  DIMENSION_NAME  DIMENSION_OWNER LEVEL_NAME SELECTED
    -- ----------- ---------  --------------  --------------- ---------- --------
    1 GLOBAL       PRICE_CUBE PRODUCT         GLOBAL           FAMILY      1
    4 GLOBAL       PRICE_CUBE PRODUCT         GLOBAL           CLASS       1
    1 GLOBAL       PRICE_CUBE TIME            GLOBAL           MONTH       1
    4 GLOBAL       PRICE_CUBE TIME            GLOBAL           QUARTER     1
    
    
  8. To create the script that will generate the fact materialized view, run the CREATEFACTMV_GS procedure.

    exec dbms_odm.createfactmv_gs
          ('global','price_cube',
           'price_cost_mv.sql','GLOBALDIR',TRUE);
    
    

    The grouping sets specified in the CREATE MATERIALIZED VIEW statement for the cube are:

    GROUP BY GROUPING SETS (
    
    (TIME_DIM.YEAR_ID, TIME_DIM.QUARTER_ID, TIME_DIM.MONTH_ID, 
     PRODUCT_DIM.TOTAL_PRODUCT_ID, PRODUCT_DIM.CLASS_ID, PRODUCT_DIM.FAMILY_ID),
     
    (TIME_DIM.YEAR_ID, TIME_DIM.QUARTER_ID, 
     PRODUCT_DIM.TOTAL_PRODUCT_ID, PRODUCT_DIM.CLASS_ID) )
    
    
  9. Go to the users/global/scripts directory and run the price_cost_mv script to create the fact materialized view.


Summary of DBMS_ODM Subprograms

Table 27-3 DBMS_ODM Subprograms

Subprogram Description

CREATECUBELEVELTUPLE Procedure


Creates a table of level combinations to be included in the materialized view for a cube.

CREATEDIMLEVTUPLE Procedure


Creates a table of levels to be included in the materialized view for a cube.

CREATEDIMMV_GS Procedure


Generates a script that creates a materialized view for each hierarchy of a dimension.

CREATEFACTMV_GS Procedure


Generates a script that creates a materialized view for the fact table associated with a cube. The materialized view includes individual level combinations that you have previously specified.

CREATESTDFACTMV Procedure


Generates a script that creates a materialized view for the fact table associated with a cube. The materialized view is automatically constructed according to general instructions that you provide.



CREATECUBELEVELTUPLE Procedure

This procedure creates the table sys.olaptableveltuples, which lists all the level combinations to be included in the materialized view for the cube. By default, all level combinations are selected for inclusion in the materialized view. You can edit the table to deselect any level combinations that you do not want to include.

Use this procedure to manually specify the grouping sets for the fact table.

Before calling this procedure, call CREATEDIMLEVTUPLE to create the table of levels for the cube.

Syntax

CREATECUBELEVELTUPLE (
               cube_owner     IN   VARCHAR2,
               cube_name      IN   VARCHAR2);

Parameters

Table 27-4 CREATECUBELEVELTUPLE Procedure Parameters

Parameter Description

cube_owner

Owner of the cube.

cube_name

Name of the cube.


See Also

"Example: Manually Choose the Grouping Sets for a Cube"


CREATEDIMLEVTUPLE Procedure

This procedure creates the table sys.olaptablevels, which lists all the levels of all the dimensions of the cube. By default, all levels are selected for inclusion in the materialized view. You can edit the table to deselect any levels that you do not want to include.

Use this procedure to manually specify the grouping sets for the fact table.

After calling this procedure, call CREATECUBELEVELTUPLE to create the table of level combinations (level tuples) for the cube.

Syntax

CREATEDIMLEVTUPLE (
               cube_owner    IN varchar2,
               cube_name     IN varchar2);

Parameters

Table 27-5 CREATEDIMLEVTUPLE Procedure Parameters

Parameter Description

cube_owner

Owner of the cube.

cube_name

Name of the cube.


See Also

"Example: Manually Choose the Grouping Sets for a Cube"


CREATEDIMMV_GS Procedure

This procedure generates a script that creates a materialized view for each hierarchy of a dimension. You must call this procedure for each dimension of a cube.

The process of creating the dimension materialized views is the same whether you generate the fact materialized view automatically or manually.


Note:

This procedure is overloaded, so that it is backwardly compatible with earlier versions that did not include the partitioning parameter.

Syntax

CREATEDIMMV_GS (
               dimension_owner    IN   VARCHAR2,
               dimension_name     IN   VARCHAR2,
               output_file        IN   VARCHAR2,
               output_path        IN   VARCHAR2,
               partitioning       IN   BOOLEAN, 
               tablespace_mv      IN   VARCHAR2 DEFAULT NULL,
               tablespace_index   IN   VARCHAR2 DEFAULT NULL);

Parameters

Table 27-6 CREATEDIMMV_GS Procedure Parameters

Parameter Description

dimension_owner

Owner of the dimension.

dimension_name

Name of the dimension.

output_file

File name for the output script.

output_path

Directory path where output_file will be created. This may be either a directory object or a path set by the UTL_FILE_DIR parameter.

partitioning

TRUE turns on partitioning; FALSE turns it off.

tablespace_mv

The name of the tablespace in which the materialized view will be created. When this parameter is omitted, the materialized view is created in the user's default tablespace.

tablespace_index

The name of the tablespace in which the index for the materialized view will be created. When this parameter is omitted, the index is created in the user's default tablespace.


See Also

"Example: Automatically Generate the Minimum Grouping Sets for a Cube"

"Example: Manually Choose the Grouping Sets for a Cube"


CREATEFACTMV_GS Procedure

This procedure generates a script that creates a materialized view for the fact table associated with a cube.

Use this procedure to manually specify the grouping sets for the fact table.

Prior to calling this procedure, you must call CREATEDIMLEVTUPLE and CREATECUBELEVELTUPLE to create the sys.olaptableveltuples table. The materialized view will include all level combinations selected in the sys.olaptableveltuples table.

Syntax

CREATEFACTMV_GS (
               cube_owner              IN   VARCHAR2,
               cube_name               IN   VARCHAR2,
               outfile                 IN   VARCHAR2,
               outfile_path            IN   VARCHAR2,
               partitioning            IN   BOOLEAN,
               tablespace_mv           IN   VARCHAR2 DEFAULT NULL,
               tablespace_index        IN   VARCHAR2 DEFAULT NULL);

Parameters

Table 27-7 CREATEFACTMV_GS Procedure Parameters

Parameter Description

cube_owner

Owner of the cube.

cube_name

Name of the cube.

output_file

File name for the output script.

output_path

Directory path where output_file will be created.This may be either a directory object or a path set by the UTL_FILE_DIR parameter.

partitioning

TRUE turns on partitioning; FALSE turns it off.

tablespace_mv

The name of the tablespace in which the materialized view will be created. When this parameter is omitted, the materialized view is created in the user's default tablespace.

tablespace_index

The name of the tablespace in which the index for the materialized view will be created. When this parameter is omitted, the index is created in the user's default tablespace.


See Also

"Manually Calculate the Grouping Sets"

"Example: Manually Choose the Grouping Sets for a Cube"


CREATESTDFACTMV Procedure

This procedure generates a script that creates a materialized view for the fact table associated with a cube.

This procedure automatically generates and updates the tables of levels and level tuples. If you want to edit these tables yourself, you must use the CREATEDIMLEVTUPLE, CREATECUBELEVELTUPLE, and CREATEFACTMV_GS procedures.

Syntax

CREATESTDFACTMV (
               cube_owner              IN   VARCHAR2,
               cube_name               IN   VARCHAR2,
               outfile                 IN   VARCHAR2,
               outfile_path            IN   VARCHAR2,
               partitioning            IN   BOOLEAN,
               materialization_level   IN   VARCHAR2,
               materialization pct     IN   NUMBER DEFAULT NULL,
               tablespace_mv           IN   VARCHAR2 DEFAULT NULL,
               tablespace_index        IN   VARCHAR2 DEFAULT NULL);

Parameters

Table 27-8 CREATESTDFACTMV Procedure Parameters

Parameter Description

cube_owner

Owner of the cube.

cube_name

Name of the cube.

outfile

File name for the output script.

outfile_path

Directory path where output_file will be created.This may be either a directory object or a path set by the UTL_FILE_DIR parameter.

partitioning

TRUE turns on partitioning; FALSE turns it off.

materialization_level

The level of materialization. This parameter identifies the level combinations that will be included in the materialized view. Specify one of the following values:

  • FULL — Fully materialize the cube's data. Include every level combination in the materialized view.

  • MINIMUM — Minimally materialize the cube's data. See "MINIMUM Grouping Sets".

  • PERCENT — Materialize the cube's data based on a percentage of the cube's level combinations. For example, consider a cube that has two dimensions with three levels and one dimension with four levels. This cube has 36 possible level combinations (3*3*4). If you choose to materialize the cube by 30%, then 12 level combinations will be included in the materialized view.

materialization_pct

The percentage of level combinations to materialize. Specify this parameter only if you have specified PERCENT for the materialization_level.

tablespace_mv

The name of the tablespace in which the materialized view will be created. When this parameter is omitted, the materialized view is created in the user's default tablespace.

tablespace_index

The name of the tablespace in which the index for the materialized view will be created. When this parameter is omitted, the index is created in the user's default tablespace.


MINIMUM Grouping Sets

If you choose minimal materialization, your fact materialized view will contain a grouping set for each of the following hierarchy combinations:

See Also

"Automatically Calculate the Grouping Sets"

"Example: Automatically Generate the Minimum Grouping Sets for a Cube"