Beruflich Dokumente
Kultur Dokumente
1-2
Copyright Oracle Corporation, 2001. All rights reserved.
Historical Trends
When you look back over these previous three major releases (7.3, 8.0, and
Oracle8i), you see some themes emerge. Oracle has focused on what most people
would consider to be 'primary requirements' for data warehousing:
• Query performance
• Scalability
• Manageability
Examples include:
• In Version 7.3, Oracle introduced bitmap indexes and hash joins to improve
Data Warehouse (DW) query performance (perhaps the most significant
primary requirement for DW).
• In Oracle 8.0, the most significant data warehousing features were
partitioning and enhancements to our parallelism. These improved both
scalability and manageability.
• Oracle8i made enhancements in many areas:
– Materialized views for performance
– New hashed and composite partitioning techniques for manageability,
scalability and query performance (solution pruning)
– Several features for manageability such as Resource Manager
– Simplified parallel query tuning
OLAP
Data Engine
Data Warehouse
Integration Engine
Engine
Mining
Engine
1-4
Copyright Oracle Corporation, 2001. All rights reserved.
1-5
Copyright Oracle Corporation, 2001. All rights reserved.
Data Warehousing
ETL
Data
OLAP
Warehouse
Engine
Data Mining
Personalization
Oracle9i
1-6
Copyright Oracle Corporation, 2001. All rights reserved.
Data Transformation
Oracle9i
1-7
Copyright Oracle Corporation, 2001. All rights reserved.
1-9
Copyright Oracle Corporation, 2001. All rights reserved.
Data Warehousing
Operational Reports
Data
ETL
Discoverer
Data
OLAP
ERP Warehouse Warehouse iAS
Builder Engine
Data Data Mining
Personalization
1-10
Copyright Oracle Corporation, 2001. All rights reserved.
2-2
Copyright Oracle Corporation, 2001. All rights reserved.
2-3
Copyright Oracle Corporation, 2001. All rights reserved.
Analytical Functions
• Inverse Percentile Functions - allow queries to find the data which corresponds
to a specified percentile value
• Hypothetical Rank and Distribution - allow queries to find what rank or
percentile value a hypothetical data value has if it is added to an existing data set
• FIRST/LAST - enables queries to specify sorted aggregate groups and return
the first or last value of each group
• WIDTH_BUCKET - the histogram bucket in which a certain input value would
fall
• Grouping sets - extensions to the GROUP BY clause that allows you to
determine which result set rows are subtotals, what is the exact level of aggregation
for a given subtotal
2-4
Copyright Oracle Corporation, 2001. All rights reserved.
Benefits
• Improved Query Speed - by using native SQL, the processing optimizations
supported by these functions enable significantly better query performance. The
performance enhancements enabled by the new functions enhance query speeds for
Oracle’s Express system and other ROLAP products.
• Enhanced Developer Productivity - the functions enable developers to perform
complex analyses with much clearer and more concise SQL code. Tasks which in
the past required multiple SQL statements or the use of procedural languages can
now be expressed using single SQL statements.
• Minimized Learning Effort - the syntax leverages existing aggregate functions,
such as SUM and AVG, so that these well-understood keywords can be used in
extended ways.
• Standardized Syntax - the new syntax is part of the ANSI SQL standard. The
new analytic functions will be supported by a large number of independent software
vendors.
2-5
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT c.channel_
c.channel_desc,
desc, avg(s.amount),
avg(s.amount),
percentile_disc(0.5)
percentile_disc(0.5) WITHIN
WITHIN GROUP
GROUP
(ORDER
(ORDER BY
BY s.amount
s.amount desc)
desc) PERCENTILE_50
PERCENTILE_50
FROM
FROM sales
sales s,
s, channels
channels cc
WHERE
WHERE c.channel_id == s.channel_id
c.channel_id s.channel_id
AND
AND time_id
time_id BETWEEN
BETWEEN '01
'01-NOV-1999'
-NOV-1999'
AND
AND '30-NOV-1999'
'30-NOV-1999'
GROUP
GROUP BY c.channel_desc;
BY c.channel_ desc;
2-6
Copyright Oracle Corporation, 2001. All rights reserved.
CHANNEL_DESC
CHANNEL_DESC AVG(S
AVG(S.AMOUNT)
.AMOUNT) PERCENTILE_50
PERCENTILE_50
--------------------
-------------------- -------------
------------- -------------
-------------
Catalog
Catalog 338.670678
338.670678 205.8
205.8
Direct
Direct Sales
Sales 254.718435
254.718435 158.4
158.4
Internet
Internet 231.018052
231.018052 187.2
187.2
Partners
Partners 308.701916
308.701916 185.4
185.4
Tele Sales
Tele Sales 90.3982314
90.3982314 48
48
2-7
Copyright Oracle Corporation, 2001. All rights reserved.
2-8
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT department_id,
department_id, ROUND(AVG(salary)),
ROUND(AVG(salary)),
RANK(10000) WITHIN GROUP
RANK(10000) WITHIN GROUP
(ORDER
(ORDER BY
BY salary
salary DESC)
DESC) RANK,
RANK,
DENSE_RANK(10000)
DENSE_RANK(10000) WITHIN
WITHIN GROUP
GROUP
(ORDER
(ORDER BY
BY salary
salary DESC)
DESC) DR
DR
FROM employees
FROM employees
GROUP
GROUP BY
BY department_id;
department_id;
2-9
Copyright Oracle Corporation, 2001. All rights reserved.
2-10
Copyright Oracle Corporation, 2001. All rights reserved.
2-11
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT manager_id,
manager_id,
MIN(salary)
MIN(salary) KEEP
KEEP (DENSE_RANK
(DENSE_RANK FIRST
FIRST ORDER
ORDER BY
BY
commission_pct) AS low_comm,
commission_pct) AS low_comm,
MAX(salary)
MAX(salary) KEEP
KEEP (DENSE_RANK
(DENSE_RANK LAST
LAST ORDER
ORDER BY
BY
commission_pct)
commission_pct) AS
AS high_comm
high_comm
FROM
FROM employees
employees
WHERE
WHERE commission_pct
commission_pct IS
IS NOT
NOT NULL
NULL
GROUP
GROUP BY
BY manager_id;
manager_id;
2-12
Copyright Oracle Corporation, 2001. All rights reserved.
MANAGER_ID
MANAGER_ID LOW_COMM
LOW_COMM HIGH_COMM
HIGH_COMM
----------
---------- ---------
--------- ---------
---------
100
100 10500
10500 14000
14000
145
145 7000
7000 10000
10000
146
146 7000
7000 10000
10000
147
147 6200
6200 10500
10500
148
148 6100
6100 11500
11500
149
149 6200
6200 11000
11000
2-13
Copyright Oracle Corporation, 2001. All rights reserved.
2-14
Copyright Oracle Corporation, 2001. All rights reserved.
WIDTH_BUCKET(input_expression,
WIDTH_BUCKET(input_expression,
low_boundary,
low_boundary, high_boundary,
high_boundary,
bucket_count)
bucket_count)
2-15
Copyright Oracle Corporation, 2001. All rights reserved.
WIDTH_BUCKET Function
For any given expression, the WIDTH_BUCKET function returns the bucket
number that the result of this expression will be assigned to after it is evaluated.
You can generate equiwidth histograms with this function. Equiwidth histograms
divide data sets into buckets with an equal interval size.
You provide the input expression, the minimum boundary value, the maximum
boundary value, and the number of buckets.
0 1 2 3 4 5 6
2-16
Copyright Oracle Corporation, 2001. All rights reserved.
WIDTH_BUCKET Example
If you ask for five buckets, you actually get seven buckets – five regular ones and
two artificial ones to catch values outside the boundary range:
• Bucket 0 holds the values less than the minimum boundary value
• Bucket 6 holds the values greater than the maximum boundary value
In the example, salaries less than 3000 are placed in bucket 0; salaries greater than
13000 are placed in bucket 6. The other salaries are placed in buckets 1 - 5,
depending on the salary value.
SELECT
SELECT last_name,
last_name, salary,
salary,
WIDTH_BUCKET(salary,3000,13000,5)
WIDTH_BUCKET(salary,3000,13000,5)
AS
AS sal_hist
sal_hist
FROM
FROM employees;
employees;
2-17
Copyright Oracle Corporation, 2001. All rights reserved.
2-18
Copyright Oracle Corporation, 2001. All rights reserved.
2-19
Copyright Oracle Corporation, 2001. All rights reserved.
Grouping Sets
A grouping set is a set of groups that the user wants the system to form.
Without the enhancements in Oracle9i, multiple queries combined together with
UNION ALL are required to achieve these tasks. A multi-query approach is
inefficient, for it requires multiple scans of the same data. The extensions to the
GROUP BY clause in Oracle9i allow the optimizer to choose better plans, enabling
the SQL execution engine to execute the query very efficiently. Users can analyze
data in one dimension without completely rolling it up, analyze across multiple
dimensions without computing the whole CUBE, or specify multiple arbitrary
groupings to meet any need.
As with the analytic functions, the GROUP BY extensions follow the international
SQL:1999 standards.
Example
• Calculate aggregates over three groupings:
– Time, Channel, Product
– Time, Channel
– Channel, Product
• Include data from the first two days of December, 1999
and for products 10, 20, and 45.
SELECT
SELECT time_id,
time_id, channel_id,
channel_id, prod_id,
prod_id,
ROUND(SUM(amount))
ROUND(SUM(amount)) ASAS cost
cost
FROM
FROM sales
sales
WHERE
WHERE (time_id
(time_id == '01
'01-DEC-1999'
-DEC-1999' or
or
time_id
time_id == '02-DEC-1999')
'02-DEC-1999')
AND
AND prod_id
prod_id IN
IN (10,
(10, 20,
20, 45)
45)
GROUP
GROUP BY
BY GROUPING
GROUPING SETS
SETS
((time_id,
((time_id, channel_id,
channel_id, prod_id),
prod_id),
(time_id,
(time_id, channel_id),
channel_id),
(channel_id,
(channel_id, prod_id))
prod_id))
®
2-20
Copyright Oracle Corporation, 2001. All rights reserved.
Grouping Sets
In the example shown, three grouping sets of data are requested:
• Time, Channel, Product
• Time, Channel
• Channel, Product
This means the resulting data will display for each of the three groups.
Note: For simplicity, only data for the first two days of December 1999, and for
the products 10, 20, and 45 are selected.
Example Results
TIME_ID
TIME_ID CC PROD_ID
PROD_ID COST
COST
-----------
----------- -- ---------
--------- ---------
---------
01-DEC-1999
01-DEC-1999 II 10
10 5673
5673
01-DEC-1999
01-DEC-1999 SS 20
20 47
47 Grouping set =
01-DEC-1999
01-DEC-1999 SS 45
45 356
356 time, channel, and
02-DEC-1999
02-DEC-1999 II 10
10 2232
2232 product
02-DEC-1999
02-DEC-1999 SS 20
20 242
242
02-DEC-1999
02-DEC-1999 SS 45
45 1624
1624
01-DEC-1999
01-DEC-1999 II 5673
5673
01-DEC-1999
01-DEC-1999 SS 403
403 Grouping set =
02-DEC-1999
02-DEC-1999 II 2232
2232 time and channel
02-DEC-1999
02-DEC-1999 SS 1865
1865
II 10
10 7905
7905
SS 20
20 289
289 Grouping set =
SS 45
45 1980
1980 channel, and product
®
2-21
Copyright Oracle Corporation, 2001. All rights reserved.
Grouping Sets
The resulting data displays cost values for each of the three groups.
The first two rows for the grouping set of time, channel and product are interpreted
as:
• On December 1, through internet sales (I), product 10 was sold for a total
cost of 5673.
• On December 1, through direct sales (S), product 20 was sold for a total cost
of 47.
The first two rows for the grouping set of time and channel are interpreted as:
• On December 1, through internet sales, total cost was 5673.
• On December 1, through direct sales, total cost was 403 (which is equal to
356 + 47).
The first two rows for the grouping set of channel and product are interpreted as:
• Through internet sales, product 10 was sold for a total cost of 7905 (which
is equal to 5673 + 2232).
• Through direct sales, product 20 was sold for a total cost of 289 (which is
equal to 47 + 242).
SELECT
SELECT time_id,
time_id, channel_id,
channel_id, prod_id,
prod_id,
round(sum(amount))
round(sum(amount)) AS cost
AS cost
FROM
FROM sales
sales
WHERE
WHERE (time_id
(time_id == '01
'01-DEC-1999'
-DEC-1999' OR
OR
time_id
time_id == '02-DEC-1999')
'02-DEC-1999')
AND
AND prod_id IN (10,
prod_id IN (10, 20,
20, 45)
45)
GROUP
GROUP BY
BY CUBE(time_id,
CUBE(time_id, channel_id,
channel_id, prod_id);
prod_id);
®
2-22
Copyright Oracle Corporation, 2001. All rights reserved.
27 rows selected.
GROUP
GROUP BY
BY time_id
time_id
UNION
UNION ALL
ALL
GROUP
GROUP BY
BY channel_id
channel_id
UNION
UNION ALL
ALL
GROUP
GROUP BY
BY prod_id;
prod_id;
®
2-23
Copyright Oracle Corporation, 2001. All rights reserved.
GROUPING SETS
Using the UNION ALL operator instead of the GROUPING SETS clause, more
scans of the base table are required, making it inefficient.
SELECT
SELECT prod_id,
prod_id, channel_id,
channel_id, time_id,
time_id,
ROUND(SUM(amount))AS
ROUND(SUM(amount))AS cost
cost
FROM
FROM sales
sales
WHERE
WHERE (time_id
(time_id == '01
'01-DEC-1999'
-DEC-1999' or
or
time_id
time_id == '02-DEC-1999')
'02-DEC-1999')
AND
AND prod_id
prod_id IN
IN (10,
(10, 20,
20, 45)
45)
GROUP
GROUP BY
BY ROLLUP
ROLLUP (prod_id,
(prod_id, (channel_id,
(channel_id, time_id));
time_id));
2-24
Copyright Oracle Corporation, 2001. All rights reserved.
Composite Columns
A composite column is a collection of columns that are treated as a unit during the
computation of groupings. You specify the columns in parenthesis. With CUBE
and ROLLUP, you do not have full control over the aggregation levels.
SELECT prod_id, channel_id, time_id, ROUND(SUM(amount))
costs
FROM sales
WHERE (time_id = '01-DEC-1999' or time_id = '02-DEC-
1999')
AND prod_id IN (10, 20, 45)
GROUP BY ROLLUP(prod_id, channel_id, time_id);
This results in computing 4 groupings:
1. (product, channel, time)
2. (product, channel)
3. (product)
4. (grand total)
The example in the slide results in three groups by creating a composite grouping
set:
GROUP BY ROLLUP(prod_id, (channel_id, time_id))
The three resultant groupings are:
(product, channel, time), (product), (grand total)
Example Results
PROD_ID
PROD_ID CC TIME_ID
TIME_ID COSTS
COSTS
---------
--------- -- ---------
--------- ---------
---------
10
10 II 01-DEC-99
01-DEC-99 5673
5673
Totals per product, channel, time
10
10 II 02-DEC-99
02-DEC-99 2232
2232
10
10 7905
7905 Total per product (10)
20
20 SS 01-DEC-99
01-DEC-99 47
47
Totals per product, channel, time
20 S 02-DEC-99
20 S 02-DEC-99 242
242
20
20 289
289 Total per product (20)
45
45 SS 01-DEC-99
01-DEC-99 356
356
Totals per product, channel, time
45
45 SS 02-DEC-99
02-DEC-99 1624
1624
45
45 1980
1980 Total per product (45)
10174
10174 Grand Total
2-25
Copyright Oracle Corporation, 2001. All rights reserved.
Composite Columns
The results show groupings for:
• (product, channel, time)
• (product)
• (grand total)
2-26
Copyright Oracle Corporation, 2001. All rights reserved.
Concatenated Groupings
Concatenated groupings offer a concise way to generate useful combinations of
groupings. Groupings specified with concatenated groupings yield the cross-
product of groupings from each grouping set. The cross-product operation enables
even a small number of concatenated groupings to generate a large number of final
groups. The concatenated groupings are specified simply by listing multiple
grouping sets, cubes, rollups, and separating them with commas.
Benefits of Concatenated Groupings
• Easy to develop
• Use by applications - SQL generated OLAP applications often involve
concatenation of grouping sets, with each grouping set defining groupings
needed for a dimension.
SELECT
SELECT prod_id,
prod_id, channel_id,
channel_id, time_id,
time_id,
ROUND(SUM(amount))
ROUND(SUM(amount)) AS costs
AS costs
FROM sales
FROM sales
WHERE
WHERE (time_id
(time_id == '01
'01-DEC-1999'
-DEC-1999' or
or
time_id
time_id == '02-DEC-1999')
'02-DEC-1999')
AND
AND prod_id IN (10, 20,
prod_id IN (10, 20, 45)
45)
GROUP BY prod_id, CUBE(channel_id),
GROUP BY prod_id, CUBE(channel_id),
ROLLUP(time_id);
ROLLUP(time_id);
2-27
Copyright Oracle Corporation, 2001. All rights reserved.
Concatenated Groupings
This results in the following groupings:
(product, channel, time), (product, channel), (product, time), (product)
2-28
Copyright Oracle Corporation, 2001. All rights reserved.
2-29
Copyright Oracle Corporation, 2001. All rights reserved.
DEPARTMENT_NAME DEPT_TOTAL
------------------------------ ----------
Sales 311500
Shipping 156400
SELECT
SELECT department_name,
department_name, SUM(salary)
SUM(salary) AS
AS dept_total
dept_total
FROM
FROM employees,
employees, departments
departments
WHERE
WHERE employees.department_id
employees.department_id ==
departments.department_id
departments.department_id
GROUP
GROUP BY
BY department_name
department_name HAVING
HAVING
SUM(salary)
SUM(salary) >> ((
SELECT
SELECT SUM(salary)
SUM(salary) ** 1/8
1/8
FROM
FROM employees,
employees, departments
departments
WHERE
WHERE employees.department_id
employees.department_id ==
departments.department_id
departments.department_id))
ORDER
ORDER BY
BY sum(salary)
sum(salary) DESC
DESC
//
2-30
Copyright Oracle Corporation, 2001. All rights reserved.
2-31
Copyright Oracle Corporation, 2001. All rights reserved.
2-32
Copyright Oracle Corporation, 2001. All rights reserved.
Business Value:
2-33
Copyright Oracle Corporation, 2001. All rights reserved.
2-34
Copyright Oracle Corporation, 2001. All rights reserved.
3-2
Copyright Oracle Corporation, 2001. All rights reserved.
3-3
Copyright Oracle Corporation, 2001. All rights reserved.
3-4
Copyright Oracle Corporation, 2001. All rights reserved.
–IN-LIST
SELECT
SELECT ** FROM
FROM LOCATIONS
LOCATIONS
WHERE
WHERE state_province IN
state_province IN ((''CA
CA'',, ''NY
NY'');
);
–Range
SELECT
SELECT **
FROM
FROM LOCATIONS
LOCATIONS WHERE
WHERE state_province
state_province <=
<= ''AZ
AZ'';;
®
3-5
Copyright Oracle Corporation, 2001. All rights reserved.
ALTER
ALTER TABLE
TABLE locations
locations
ADD
ADD PARTITION region_nonmainland
PARTITION region_nonmainland
VALUES
VALUES ((''HI
HI'',, ''PR
PR''))
STORAGE
STORAGE (INITIAL
(INITIAL 20K
20K NEXT
NEXT 20K)
20K)
TABLESPACE tbs_3
TABLESPACE tbs_3
NOLOGGING;
NOLOGGING;
3-6
Copyright Oracle Corporation, 2001. All rights reserved.
ALTER
ALTER TABLE
TABLE locations
locations
MERGE
MERGE PARTITIONS
PARTITIONS
region_northwest,
region_northwest, region_southwest
region_southwest
INTO
INTO PARTITION
PARTITION region_west
region_west
PCTFREE
PCTFREE 50
50 STORAGE(MAXEXTENTS
STORAGE(MAXEXTENTS 20);
20);
3-8
Copyright Oracle Corporation, 2001. All rights reserved.
ALTER
ALTER TABLE
TABLE locations
locations
MODIFY
MODIFY PARTITION
PARTITION region_
region_south
south
ADD
ADD VALUES
VALUES ((''OK
OK'',, ''KS
KS'')) ;;
3-10
Copyright Oracle Corporation, 2001. All rights reserved.
DELETE
DELETE locations
locations
where
where state_province
state_province in
in ((''OK
OK'',, ''KS
KS'')) ;;
ALTER
ALTER TABLE
TABLE locations
locations
MODIFY
MODIFY PARTITION
PARTITION region_
region_south
south
DROP
DROP VALUES
VALUES ((''OK
OK'',, ''KS
KS'')) ;;
3-11
Copyright Oracle Corporation, 2001. All rights reserved.
3-13
Copyright Oracle Corporation, 2001. All rights reserved.
3-15
Copyright Oracle Corporation, 2001. All rights reserved.
3-17
Copyright Oracle Corporation, 2001. All rights reserved.
3-18
Copyright Oracle Corporation, 2001. All rights reserved.
CREATE
CREATE VIEW
VIEW DEP
DEPT10_EMPLOYEES
T10_EMPLOYEES ((
id
id PRIMARY
PRIMARY KEY
KEY RELY
RELY DISABLE
DISABLE NOVALIDATE
NOVALIDATE ,,
first_name, last_name, email
first_name, last_name, email ) )
AS
AS
SELECT
SELECT employee_id,
employee_id, first_name,
first_name, last_name,
last_name, email
email
FROM EMPLOYEES
FROM EMPLOYEES
WHERE
WHERE department_id
department_id == 10;
10;
CREATE
CREATE VIEW
VIEW DEP
DEPT30_EMPLOYEES
T30_EMPLOYEES ((
id,
id, first_name, last_name,
first_name, last_name, email,
email,
CONSTRAINT pk_d30e
CONSTRAINT pk_d30e
PRIMARY
PRIMARY KEY
KEY (id)
(id) RELY
RELY DISABLE
DISABLE NOVALIDATE
NOVALIDATE ))
AS
AS
SELECT
SELECT employee_id,
employee_id, first_name,
first_name, last_name,
last_name, email
email
FROM EMPLOYEES
FROM EMPLOYEES
WHERE
WHERE department_id
department_id == 30;
30;
®
3-19
Copyright Oracle Corporation, 2001. All rights reserved.
ALTER
ALTER VIEW
VIEW DEPT10_EMPLOYEES
DEPT10_EMPLOYEES
ADD
ADD CONSTRAINT u_d10e
CONSTRAINT u_d10e
UNIQUE
UNIQUE (email)
(email) RELY
RELY DISABLE
DISABLE NOVALIDATE;
NOVALIDATE;
ALTER
ALTER VIEW
VIEW DEPT30_EMPLOYEES
DEPT30_EMPLOYEES
DROP
DROP CONSTRAINT
CONSTRAINT pk_
pk_d30e;
d30e;
ALTER
ALTER VIEW
VIEW DEPT10_EMPLOYEES
DEPT10_EMPLOYEES
DROP
DROP PRIMARY
PRIMARY KEY
KEY;;
ALTER
ALTER VIEW
VIEW DEPT
DEPT10_EMPLOYEES
10_EMPLOYEES
MODIFY
MODIFY CONSTRAINT
CONSTRAINT u_d10e
u_d10e NORELY
NORELY;;
®
3-20
Copyright Oracle Corporation, 2001. All rights reserved.
CREATE
CREATE TABLE
TABLE TEST
TEST (( seq
seq number,
number, test
test char(50),
char(50),
id number REFERENCES DEPT20_EMPLOYEES
id number REFERENCES DEPT20_EMPLOYEES
RELY
RELY DISABLE
DISABLE NOVALIDATE
NOVALIDATE);
);
DROP
DROP VIEW
VIEW DEPT20_EMPLOYEES
DEPT20_EMPLOYEES CASCADE
CASCADE CONSTRAINTS
CONSTRAINTS;;
®
3-21
Copyright Oracle Corporation, 2001. All rights reserved.
3-22
Copyright Oracle Corporation, 2001. All rights reserved.
3-23
Copyright Oracle Corporation, 2001. All rights reserved.
• Join Order
• Join Methods
• Access Methods
• Distribution Methods
• Query Rewrite
• View/Subquery Merging
3-25
Copyright Oracle Corporation, 2001. All rights reserved.
Editable Attributes
• Join Order: Join order defines the sequence in which tables are joined during query execution.
This includes tables produced by evaluating subqueries and views as well as tables appearing in the
FROM clauses of subqueries and views.
• Join Methods: Join methods define the methods used to join tables during query execution.
Examples are nested loops join and sort-merge join.
• Access Methods: Access methods define the methods used to retrieve table data from the
database. Examples are indexed access and full table scan.
• Distributed Execution Plans: Distributed queries have execution plans that are generated for
each site at which some portion of the query is executed. The execution plan for the local site at
which the query is submitted can be controlled by plan stability and equivalent plans must be
produced at that site. In addition, driving site selection can be controlled centrally even though it
might normally change when certain schema changes are made.
• Distribution Methods: For parallel query execution, distribution methods define how the inputs
to execution nodes are partitioned.
• View and Subquery Merging and Summary Rewrite: The topic of View and Subquery
Merging and Summary Rewrite is meant to include all transformations in which objects and/or
operations that occur in one subquery of the original SQL statement are caused to migrate to a
different subquery for execution. Summary rewrite may also cause one set of objects and/or
operations to be replaced by another.
• Public Outlines
– Default Setting when Creating Outlines
– Stored in the OUTLN Schema
– Used when USE_STORED_OUTLINES is set to
TRUE
• Private Outlines
– Stored in User's Schema
– Can be Edited
– Used when USE_PRIVATE_OUTLINES is set to
TRUE
– Changes can be saved to Public
3-26
Copyright Oracle Corporation, 2001. All rights reserved.
Outline Cloning
• Public Outlines: In Oracle8i, all outlines are public objects indirectly available to all users on the
system for whom the USE_STORED_OUTLINES configuration parameter setting applies. Outline
data resides in the OUTLN schema that can be thought of as an extension to the SYS schema in the
sense that it is maintained and consumed by the system only. Users have been discouraged from
manipulating this data directly to avoid security and integrity issues associated with outline data.
Outlines will continue to be public by default and only public outlines are generally available to the
user community.
• Private Outlines: In Oracle9i, the notion of a private outline to aid in outline editing is
introduced. A private outline is an outline seen only in the current session and whose data resides in
the current parsing schema. By storing the outline data for a private outline directly in the user’s
schema, users are given the opportunity to directly manipulate the outline data through DML in
whatever way they choose. Any changes made to such an outline are not seen by any other session
on the system and applying a private outline to the compilation of a statement can only be done in the
current session through a new session parameter. Only when a user explicitly chooses to save edits
back to the public area will the rest of the users see them.
An outline clone is a private outline that has been created by copying data from an existing outline.
3-27
Copyright Oracle Corporation, 2001. All rights reserved.
• Where :
– TRUE enables use of private outlines in the
DEFAULT category
– FALSE disables use of private outlines
– category_name enables use of private
outlines in the named category
®
3-28
Copyright Oracle Corporation, 2001. All rights reserved.
Configuration Parameters
The USE_PRIVATE_OUTLINESsession parameter is added to control the use of private outlines
instead of public outlines. When an outlined SQL command is issued, this parameter will cause
outline retrieval to come from the session private area rather than the public area normally consulted
as per the setting of USE_STORED_OUTLINES. If no outline exists in the session private area, no
outline will be used for the compilation of the command.
You can specify a value for this session parameter by using the following syntax :
ALTER SESSION SET USE_PRIVATE_OUTLINES = {TRUE | FALSE |
category_name}
Where :
• TRUE enables use of private outlines and defaults to the DEFAULT category
• FALSE disables use of private outlines
• category_name enables use of private outlines in the named category
When a user begins an outline editing session, the parameter should be set to the category to which
the outline being edited belongs. This enables the feedback mechanism in that it allows the private
outline to be applied to the compilation process.
Upon completion of outline editing, this parameter should be set to false to restore the session to
normal outline lookup as dictated through the USE_STORED_OUTLINES parameter.
3-29
Copyright Oracle Corporation, 2001. All rights reserved.
3-30
Copyright Oracle Corporation, 2001. All rights reserved.
dbms_outln_edit.refresh_private_outline(
dbms_outln_edit.refresh_private_outline( 'private_outline1
'private_outline1')
')
®
3-31
Copyright Oracle Corporation, 2001. All rights reserved.
3-32
Copyright Oracle Corporation, 2001. All rights reserved.
3-33
Copyright Oracle Corporation, 2001. All rights reserved.
3-34
Copyright Oracle Corporation, 2001. All rights reserved.
Outline Editor
Although outlines are currently shipping (introduced in Oracle8i) and users can create, delete and
copy them manually using SQL (and can potentially create a great number of them by automatically
generating them using “ALTER SESSION SET CREATE_STORED_OUTLINES = TRUE”), there
is currently no convenient way to manage outlines.
Oracle9i gives users the ability to manage their outlines directly using new outline management GUI
functionality, the “Outlines Window”, to browse, sort, delete, export and import them. Users are also
able to tell if an outline, once defined or imported, has been used, or continues to be used after a
database or application upgrade, and are able to change the category of a group of outlines.
The Outlines Window is accessible via SQL Analyze (the primary interface for dealing with
outlines) and the console. Because outlines are primarily used for tuning SQL statements, users
create (other than through SQL), edit, analyze and compare them using the Outline Editor
functionality of SQL Analyze.
3-35
Copyright Oracle Corporation, 2001. All rights reserved.
4-2
Copyright Oracle Corporation, 2001. All rights reserved.
Merge Into
Staging Table 3 Warehouse Warehouse Table
Tables
INSERT & UPDATE
4-3
Copyright Oracle Corporation, 2001. All rights reserved.
External Table
Flat Files
Table Functions
Merge Into
Validate Data Transform Data Warehouse
Tables
UPSERT
Warehouse Table
4-4
Copyright Oracle Corporation, 2001. All rights reserved.
4-5
Copyright Oracle Corporation, 2001. All rights reserved.
External tables :
• Allow external data to be queried and joined directly
and in parallel without requiring it to be loaded into the
database.
• Eliminate the need for staging the data within the
database for ETL in data warehousing applications
• Are useful in environments where an external source
has to be joined with database objects and then
transformed
• Are useful when the external data is large and not
queried frequently
• Complement SQL*Loader functionalities
4-6
Copyright Oracle Corporation, 2001. All rights reserved.
4-7
Copyright Oracle Corporation, 2001. All rights reserved.
In the example above an external table named employees_ext is defined. Delta_dir is a directory
where the external flat files are residing. This example also use the default access driver for this
implementation of external tables. It is called oracle_loader.The access parameters control the
extraction of data from the flat file using record and file formatting information. The directory object
was introduced in Oracle8i.
Oracle9i
Flat Files
4-8
Copyright Oracle Corporation, 2001. All rights reserved.
• DBA_EXTERNAL_TABLES • DBA_EXTERNAL_LOCATIONS
- OWNER – OWNER
- NAME – TABLE_NAME
- TYPE_OWNER – LOCATION
- TYPE_NAME – DIRECTORY_OWNER
- DEFAULT_DIRECTORY_ OWNER – DIRECTORY_NAME
- DEFAULT_DIRECTORY_ NAME
- REJECT_LIMIT
4-9
Copyright Oracle Corporation, 2001. All rights reserved.
4-10
Copyright Oracle Corporation, 2001. All rights reserved.
4-11
Copyright Oracle Corporation, 2001. All rights reserved.
PARALLEL_ENABLE is an optimization hint indicating that the function can be executed in parallel.
The function should not use session state, such as package variables, as those variables may not be
shared among the parallel execution servers.
The optional PARTITION argument BY clause is used only with functions that have a REF
CURSOR argument type. It lets you define the partitioning of the inputs to the function from the REF
CURSOR argument. Partitioning the inputs to the function affects the way the query is parallelized
when the function is used as a table function (that is, in the FROM clause of the query). ANY indicates
that the data can be partitioned randomly among the parallel execution servers. Alternatively, you can
specify RANGE or HASH partitioning on a specified column list.
SELECT *
FROM TABLE(transform(cursor(SELECT *
FROM order_items_ext)));
4-12
Copyright Oracle Corporation, 2001. All rights reserved.
4-13
Copyright Oracle Corporation, 2001. All rights reserved.
4-14
Copyright Oracle Corporation, 2001. All rights reserved.
Note: The multi-table insert statement can be performed with or without direct-load, and with or
without parallelization for faster performance. In general, the rules are the same as for the single-
table INSERT statement. The idea is that all corresponding tables will be direct-loaded/parallelized,
or none of them will be. That is why, all you need to specify is the APPEND/PARALLEL hint without
specifying tables names.
Oracle9i Business Intelligence (Beta) Page 4-14
Advantages of Multi-table INSERTs
4-15
Copyright Oracle Corporation, 2001. All rights reserved.
• Unconditional INSERT
• Pivoting INSERT
• Conditional ALL INSERT
• Conditional FIRST INSERT
4-16
Copyright Oracle Corporation, 2001. All rights reserved.
Note: This feature is an Oracle extension to SQL and is not a SQL: 1999 standard.
INSERT ALL
INTO product_activity VALUES(today, product_id,
quantity)
INTO product_sales VALUES(today, product_id, total)
SELECT trunc(order_date) today, product_id,
SUM(unit_price) total, SUM(quantity) quantity
FROM orders, order_items
WHERE orders.order_id = order_items.order_ id AND
order_date = TRUNC(SYSDATE)
GROUP BY product_id;
4-17
Copyright Oracle Corporation, 2001. All rights reserved.
4-18
Copyright Oracle Corporation, 2001. All rights reserved.
INSERT ALL
WHEN product_id IN (SELECT product_id
FROM promotional_items)
INTO promotional_sales VALUES(product_id,list_price)
WHEN order_mode = 'online'
INTO web_orders VALUES(product_id, order_total)
SELECT product_id, list_price , order_total, order_mode
FROM orders;
4-19
Copyright Oracle Corporation, 2001. All rights reserved.
4-20
Copyright Oracle Corporation, 2001. All rights reserved.
• MERGE statements
– provide the ability to conditionally UPDATE/INSERT
into the database
– Do an UPDATE if the row exists and an INSERT if it is
a new row
– Avoid multiple updates
– Can be used in Data Warehousing applications
4-21
Copyright Oracle Corporation, 2001. All rights reserved.
4-22
Copyright Oracle Corporation, 2001. All rights reserved.
4-23
Copyright Oracle Corporation, 2001. All rights reserved.
Example of MERGE
This is an example of using MERGEs in data warehousing. Customer(C) is a large fact table and
cust_src is a smaller "delta" table with rows which need to be inserted into customer
conditionally. This MERGE statement indicates that table customer has to be MERGEed with the rows
returned from the evaluation of the ON clause of the MERGE. The USING clause in this case is the
table cust_src (S), but it can be an arbitrary query. Each row from S is checked for a match to
any row in C by satisfying the join condition specified by the On clause. If so, each row in C is
updated using the UPDATE SET clause of the MERGE statement. If no such row exists in C then the
rows are inserted into table Causing the ELSE INSERT clause.
4-24
Copyright Oracle Corporation, 2001. All rights reserved.
4-25
Copyright Oracle Corporation, 2001. All rights reserved.
SYNC_SET Subscriber
Subscriber
Change Set
View 1 View 2
C1 C2 C3 C4 C1 C2 C3 C5 C6 C7 C8 C1 C4 C7 C8
4-27
Copyright Oracle Corporation, 2001. All rights reserved.
Note: With synchronous data capture, internal triggers are used to generate the
change data as data manipulation language (DML) operations are made to the
database on the source system. Every time a DML operation occurs on a source
table, the internal trigger is executed and writes a record of that operation to the
change table.
4-29
Copyright Oracle Corporation, 2001. All rights reserved.
• Introduced in Oracle8i
• New in Oracle9i: Source and target databases can
have different block sizes
• Especially useful for transporting from OLTP to
warehouse
• Same limitations as in Oracle8i except for the
different block sizes limitation
• Refer to the Memory Management Lesson in the
Server Manageability module for more info on how
to setup different block sizes in the same database
• Use the same procedures defined in Oracle8i to
transport a tablespace to a database with a different
block size
®
4-30
Copyright Oracle Corporation, 2001. All rights reserved.
4-32
Copyright Oracle Corporation, 2001. All rights reserved.
Partition 1 Partition 2
DML DML
Slave Slave
Partition 1 Partition 2
Repartitioning
4-33
Copyright Oracle Corporation, 2001. All rights reserved.
4-35
Copyright Oracle Corporation, 2001. All rights reserved.
SQL*Loader Enhancements
In Oracle9i, SQL*Loader allows for correctly loading integer and zoned/packed
decimal datatypes across platforms. This means that SQL*Loader now has the
ability to do the following:
• Load binary integer data created on a platform whose byte ordering is
different than that of the target platform: INTEGER(n) is a full-word binary
integer, where n is an optionally-supplied length of 1, 2, 4, or 8. If no length
specification is given, then the length, in bytes, is based on the size of a LONG
INT C on your particular platform. An INTEGER that is specified without a
length specification is nonportable. However, if INTEGER is specified with a
length specification (n) and the BYTEORDER keyword, it is portable. Specifying
an explicit length for binary integers is useful in situations where the input data
was created on a platform whose word length differs from that on which
SQL*Loader is running. For instance, input data containing binary integers
might be created on a 64-bit platform and loaded into a database using
SQL*Loader on a 32-bit platform. In this case, INTEGER(8) should be used
in order to instruct SQL*Loader to process the integers as 8-byte quantities, not
as 4-byte quantities.
• Load binary floating-point data created on a platform whose byte ordering is
different than that of the target platform (provided the floating-point format
used by source and target systems is the same)
• Specify the size, in bytes, of a binary integer and load it regardless of the
target platform's native integer size
• Specify that integer values are to be treated as signed or unsigned quantities
• Accept EBCDIC-based zoned/packed decimal data encoded in IBM format
4-37
Copyright Oracle Corporation, 2001. All rights reserved.
DECLARE
TYPE numtab IS table of number;
v_deptid numtab :=
numtab(10,0,11,12,30,0,20,199,2,0,9,1);
total_error NUMBER;
BEGIN
FORALL i IN v_deptid.first .. v_deptid.last
SAVE EXCEPTIONS
DELETE from employees where salary >
500000/v_deptid(i);
total_error := SQL%BULK_EXCEPTIONS.COUNT ;
4-38
Copyright Oracle Corporation, 2001. All rights reserved.
4-39
Copyright Oracle Corporation, 2001. All rights reserved.
DECLARE
TYPE CoordsTab IS TABLE OF Coords;
pairs CoordsTab;
BEGIN
SELECT loc BULK COLLECT INTO pairs FROM grid;
-- now pairs contains (1,2) and (3,4)
END;
4-40
Copyright Oracle Corporation, 2001. All rights reserved.
4-41
Copyright Oracle Corporation, 2001. All rights reserved.
DECLARE
TYPE num_tab IS TABLE OF NUMBER;
type trc IS REF CURSOR;
rc trc;
ids num_tab;
BEGIN
EXECUTE IMMEDIATE 'select employee_id
from employees'
BULK COLLECT INTO ids;
END;
4-42
Copyright Oracle Corporation, 2001. All rights reserved.
DECLARE
TYPE num_tab IS TABLE OF NUMBER;
TYPE char_tab is TABLE OF VARCHAR2(30);
ids num_tab := num_tab (12,13,14,15);
names char_tab := char_tab('R/D','IT','GL','PR');
BEGIN
FORALL iter IN 1..4
EXECUTE IMMEDIATE
'INSERT INTO departments(department_id,
department_name)VALUES(:1, :2)'
USING ids(iter), names(iter);
END;
4-43
Copyright Oracle Corporation, 2001. All rights reserved.
DECLARE
TYPE num_tab IS TABLE OF NUMBER;
sql_str VARCHAR2(200);
v_sal NUMBER := 10000;
saltab num_tab;
BEGIN
sql_str := 'UPDATE employees SET salary = :1
WHERE department_id = 10
RETURNING salary INTO :2';
EXECUTE IMMEDIATE sql_str
USING v_sal RETURNING BULK COLLECT INTO
saltab;
END;
®
4-44
Copyright Oracle Corporation, 2001. All rights reserved.
4-45
Copyright Oracle Corporation, 2001. All rights reserved.
5-2
Copyright Oracle Corporation, 2001. All rights reserved.
start end
key bitmap
ROWID ROWID
10.8000.3 <Rognes, 1.2.3, 10.8000.3, 1000100100010010100…>
<Aix-en-Provence, 1.2.3, 10.8000.3, 0001010000100100000…>
<Marseille, 1.2.3, 10.8000.3, 0100000011000001001…>
……………………………………
SELECT SUM(S.amount_sold)
Only the index and Sales
FROM Sales S, Customers C
WHERE S.cust_id = table are used to evaluate
C.cust_id the query. No join with
AND C.cust_city = 'Aix-en-Provence'; Customers table is needed!
®
5-3
Copyright Oracle Corporation, 2001. All rights reserved.
5-5
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT SUM(S.amount_sold)
FROM Sales S, Customers C, Products P
WHERE S.cust_id = C.cust_id AND
S.prod_id = P.prod_id AND
C.cust_gender = 'MALE' AND
P.prod_category = 'MOBILE'
Products
5-6
Copyright Oracle Corporation, 2001. All rights reserved.
Note: The above example is just here to clarify the syntax possibilities. Indeed, in
the above case, it might be interesting to consider the creation of two different
bitmap join indexes instead of just one as this could led to an explosion in the
number of indexes (one for each query). Whereas, creating one bitmap join index
on the SALES table for CUST_GENDER and one bitmap join index on SALES for
PROD_CATEGORY also allow the optimizer to use both indexes for the above
query. This will be, of course, less efficient than the above solution but has the
great advantage to also allow queries only between SALES and CUSTOMERS, or
SALES and PRODUCTS for example.
5-7
Copyright Oracle Corporation, 2001. All rights reserved.
New way :
– OPTIMIZER_MODE =
– FIRST_ROWS_1
– FIRST_ROWS_10
– FIRST_ROWS_100
– FIRST_ROWS_1000
– ALTER SESSION SET OPTIMIZER_GOAL =
FIRST_ROWS_n
– /*+ FIRST_ROWS(x) */
– x can be any positive integer
5-8
Copyright Oracle Corporation, 2001. All rights reserved.
5-9
Copyright Oracle Corporation, 2001. All rights reserved.
5-11
Copyright Oracle Corporation, 2001. All rights reserved.
5-13
Copyright Oracle Corporation, 2001. All rights reserved.
5-14
Copyright Oracle Corporation, 2001. All rights reserved.
If appropriate, you can switch between the statistics gathered. Note that it is
possible to automate this process by submitting a job to update the dictionary with
appropriate statistics: During the day, a job may import the OLTP statistics for the
daytime run and during the night, an other job imports the OLAP statistics for the
nighttime run.
5-15
Copyright Oracle Corporation, 2001. All rights reserved.
5-16
Copyright Oracle Corporation, 2001. All rights reserved.
5-17
Copyright Oracle Corporation, 2001. All rights reserved.
5-18
Copyright Oracle Corporation, 2001. All rights reserved.
MESSAGE
------------------------------------
QSM-01001: query rewrite not enabled
5-19
Copyright Oracle Corporation, 2001. All rights reserved.
5-20
Copyright Oracle Corporation, 2001. All rights reserved.
5-22
Copyright Oracle Corporation, 2001. All rights reserved.
load_ workload
MVIEW_FILTER purge_results
MVIEW_WORKLOAD
advisor_detail_report Report
purge_ workload
MVIEW_RECOMMENDATIONS
recommend_mv_w Script
generate_mv_script
®
5-24
Copyright Oracle Corporation, 2001. All rights reserved.
Application Query
SELECT s.store_name,
SUM(f.amount) SELECT
as sum_sales m.store_name,
FROM sales f, store s REWRITE m.sum_sales
WHERE s.store_key = f.store_key FROM
AND s.city = 'Boston' sales_boston m;
GROUP BY s.store_name;
5-26
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT s.city,
s.city, s.store_strength,
s.store_strength, SUM(f.
SUM(f.amount)
amount)
FROM store s, sales
FROM store s, sales f f
WHERE
WHERE s.store_key
s.store_key == f.store_key
f.store_key AND
AND
s.store_strength
s.store_strength >
> 50 AND s.store_strength << 100
50 AND s.store_strength 100
GROUP
GROUP BY
BY s.city,
s.city, s.store_strength;
s.store_strength;
5-27
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT s.city,
s.city, s.store_strength,
s.store_strength, SUM(f.
SUM(f.amount)
amount)
FROM
FROM store
store s,
s, sales
sales ff
WHERE
WHERE s.store_key
s.store_key == f.store_key
f.store_key AND
AND
s.store_strength
s.store_strength >> 50
50 AND
AND s.store_strength
s.store_strength << 100
100
GROUP BY s.city, s.store_strength;
GROUP BY s.city, s.store_strength;
total_sales Materialized View Query ®
5-28
Copyright Oracle Corporation, 2001. All rights reserved.
Application Query
SELECT
SELECT
COUNT(f.amount)
COUNT(f.amount) SELECT
SELECT
FROM
FROM sales
sales f,
f, product
product pp SUM(m.cnt_sales)
SUM(m.cnt_sales)
WHERE
WHERE f.product_key ==
f.product_key REWRITE FROM
FROM mv_car_color
mv_car_color
p.product_key
p.product_key WHERE
WHERE m.color
m.color in
in
AND
AND p.color in
p.color in ('red',
('red', 'green');
'green');
('red'
('red' ,'green');
,'green');
SELECT
SELECT p.color,
p.color, COUNT(f.amount)
COUNT(f.amount) as
as cnt_sales
cnt_sales
FROM
FROM sales
sales f,
f, product
product pp
WHERE
WHERE f.product_key
f.product_key == p.product_key
p.product_key AND
AND
p.color
p.color in
in ('red'
('red' ,'green'
,'green' ,'blue')
,'blue')
GROUP
GROUP BY
BY p.color;
p.color;
5-29
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT p.category_id,
p.category_id, SUM(f.amount)
SUM(f.amount) as
as sales
sales
FROM
FROM sales
sales f,
f, product
product pp
WHERE
WHERE f.product_key
f.product_key == p.product_key
p.product_key
AND
AND p.category_id LIKE 'AB%'
p.category_id LIKE 'AB%'
GROUP
GROUP BY
BY p.category_id;
p.category_id;
mvproducts Materialized View Query
®
5-30
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT s.city,
s.city, SUM(f.amount)
SUM(f.amount) asas sum_sales,
sum_sales,
s.store_strength
s.store_strength
FROM
FROM store
store s,
s, sales
sales ff
WHERE
WHERE s.store_key == f.store_key
s.store_key f.store_key AND
AND
s.store_strength
s.store_strength IS
IS NOT
NOT NULL
NULL
GROUP
GROUP BY
BY s.city;
s.city;
mv_non_null Materialized View Query
®
5-31
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT s.city,
s.city, s.city_tax
s.city_tax ++ s.regional_tax
s.regional_tax ++ s.sales_tax
s.sales_tax,,
SUM(f.amount) as sum_sales
SUM(f.amount) as sum_sales
FROM
FROM store
store s,
s, sales
sales ff
WHERE
WHERE s.store_key == f.store_key
s.store_key f.store_key
AND
AND (s.city_tax
(s.city_tax ++ s.regional_tax
s.regional_tax ++ s.sales_tax
s.sales_tax )) >> 22
GROUP
GROUP BY s.city, s.city_tax + s.regional_tax+ s.sales_tax;
BY s.city, s.city_tax + s.regional_tax+ s.sales_tax;
sales_hightax Materialized View Query ®
5-32
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT p.color,
p.color, COUNT(f.amount)
COUNT(f.amount) as
as cnt_sales
cnt_sales
FROM sales f, product
FROM sales f, product p p
WHERE
WHERE f.product_key
f.product_key == p.product_key
p.product_key
AND
AND (( p.color = 'red') OR
(( p.color = 'red') OR (p.
(p. color
color == 'green')
'green')
OR
OR (p.
(p. color
color == 'blue'))
'blue'))
GROUP
GROUP BY
BY p.color;
p.color;
5-33
Copyright Oracle Corporation, 2001. All rights reserved.
5-34
Copyright Oracle Corporation, 2001. All rights reserved.
5-35
Copyright Oracle Corporation, 2001. All rights reserved.
CREATE
CREATE TABLE
TABLE sales
sales (date_entered
(date_entered DATE,
DATE, …… ))
PARTITION
PARTITION BY
BY RANGE
RANGE (date_entered)
(date_entered)
(( PARTITION
PARTITION fact_part1 VALUES
fact_part1 VALUES LESS
LESS THAN
THAN ('1-APR-1999'),
('1-APR-1999'),
PARTITION
PARTITION fact_part2
fact_part2 VALUES
VALUES LESS
LESS THAN
THAN ('1-JUL-1999'),
('1-JUL-1999'),
PARTITION fact_part3 VALUES LESS THAN ('1-OCT-1999'),
PARTITION fact_part3 VALUES LESS THAN ('1-OCT-1999'),
PARTITION
PARTITION fact_part4
fact_part4 VALUES
VALUES LESS
LESS THAN
THAN ('1-JAN-2000'),
('1-JAN-2000'),
…… );
);
CREATE
CREATE TABLE
TABLE store
store (store_id
(store_id NUMBER,
NUMBER,
region_id
region_id NUMBER,
NUMBER, …… ))
PARTITION BY RANGE (store_id)
PARTITION BY RANGE (store_id)
(( PARTITION
PARTITION store_part1
store_part1 VALUES
VALUES LESS
LESS THAN
THAN (1000),
(1000),
PARTITION store_part2 VALUES LESS THAN (2000),
PARTITION store_part2 VALUES LESS THAN (2000),
PARTITION
PARTITION store_part3
store_part3 VALUES
VALUES LESS
LESS THAN
THAN (MAXVALUE));
(MAXVALUE));
5-37
Copyright Oracle Corporation, 2001. All rights reserved.
5-38
Copyright Oracle Corporation, 2001. All rights reserved.
5-39
Copyright Oracle Corporation, 2001. All rights reserved.
5-40
Copyright Oracle Corporation, 2001. All rights reserved.
2. Can be rewritten :
SELECT
SELECT m.city,
m.city, SUM(m.sum_sales)
SUM(m.sum_sales)
FROM
FROM store_id_sales mm
store_id_sales
WHERE
WHERE m.p_marker
m.p_marker == 'STORE_PART1'
'STORE_PART1'
AND
AND m.store_name = 'Sears'
m.store_name = 'Sears'
GROUP
GROUP BY
BY m.city;
m.city;
5-42
Copyright Oracle Corporation, 2001. All rights reserved.
Application Query
SELECT
SELECT city,
city,
SELECT
SELECT s.city,
s.city, s.zipcode,
s.zipcode, zipcode,
zipcode,
SUM(f.amount)
SUM(f.amount) sum_sales
sum_sales
FROM
FROM store
store s,
s, sales
sales ff
REWRITE FROM
FROM mv_cube
mv_cube
WHERE
WHERE s.store_key ==
s.store_key
WHERE
WHERE cc == 00 and
and
f.store_key
f.store_key zz == 0;
0;
GROUP
GROUP BY s.city,
BY s.city, s.zipcode;
s.zipcode;
SELECT
SELECT s.city,
s.city, s.zipcode,
s.zipcode,
SUM(f.amount)
SUM(f.amount) as
as sum_sales,
sum_sales,
GROUPING(s.city)
GROUPING(s.city) as
as c,
c, GROUPING(s.zipcode)
GROUPING(s.zipcode) as
as zz
FROM store s, sales
FROM store s, sales f f
WHERE
WHERE s.store_key
s.store_key == f.store_key
f.store_key
GROUP
GROUP BY CUBE (s.city, s.zipcode);
BY CUBE (s.city, s.zipcode);
5-43
Copyright Oracle Corporation, 2001. All rights reserved.
SELECT
SELECT product,
product, region,
region, time,GROUPING_ID()
time,GROUPING_ID() as
as gid
gid,,
sum(sales)
sum(sales) as
as sum_sales
sum_sales
FROM
FROM salesTable
salesTable
GROUP
GROUP BY
BY GROUPING
GROUPING SETS
SETS ((product,
((product, region,
region, time),
time),
(product,
(product, region),
region),
(product));
(product));
5-44
Copyright Oracle Corporation, 2001. All rights reserved.
5-45
Copyright Oracle Corporation, 2001. All rights reserved.
5-46
Copyright Oracle Corporation, 2001. All rights reserved.