Oracle® OLAP Reference 10g Release 2 (10.2) Part Number B14350-01 |
|
|
View PDF |
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.
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;
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');
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.
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.
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
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.
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
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) )
Go to the users/global/scripts
directory and run the price_cost_mv
script to create the fact materialized view.
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. |
|
Creates a table of levels to be included in the materialized view for a cube. |
|
Generates a script that creates a materialized view for each hierarchy of a dimension. |
|
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. |
|
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. |
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 |
---|---|
|
Owner of the cube. |
|
Name of the cube. |
See Also
"Example: Manually Choose the Grouping Sets for a Cube"
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 |
---|---|
|
Owner of the cube. |
|
Name of the cube. |
See Also
"Example: Manually Choose the Grouping Sets for a Cube"
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 thepartitioning 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
See Also
"Example: Automatically Generate the Minimum Grouping Sets for a Cube"
"Example: Manually Choose the Grouping Sets for a Cube"
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
See Also
"Manually Calculate the Grouping Sets"
"Example: Manually Choose the Grouping Sets for a Cube"
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 |
---|---|
|
Owner of the cube. |
|
Name of the cube. |
|
File name for the output script. |
|
Directory path where |
|
|
|
The level of materialization. This parameter identifies the level combinations that will be included in the materialized view. Specify one of the following values:
|
|
The percentage of level combinations to materialize. Specify this parameter only if you have specified |
|
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. |
|
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:
The top level of each hierarchy
One level above the lowest of each hierarchy
Top level of one hierarchy and the lowest level of all other hierarchies.
One level above the lowest of one hierarchy and the lowest level of all other hierarchies.
See Also
"Automatically Calculate the Grouping Sets"
"Example: Automatically Generate the Minimum Grouping Sets for a Cube"