Title Slide
Learn How To Partition
In Oracle 9i Release 2
Reference Number: #31316
By
Eric Yen
System Consultant
Quest Software
1 of 31
Agenda
• Partitioning Defined
• Evolution of Partitioning in Oracle
• When to partition tables
• Range Partitioning
• Hash Partitioning
• List Partitioning
• Composite
– Range-Hash
– Range-List
2 of 31
Agenda
• Globally Partitioned Indexes
• Locally Partitioned Indexes
• Bringing It All Together
• Other Sources Of Information
• Summary
• Questions and Answers
• Short Survey . . . How did I do?
3 of 31
Partitioning Defined
• The concept of Divide and Conquer.
• Breaking down a large problem into
smaller manageable pieces.
• Making a mountain into a mole hill.
• Your definition here.
• “Dividing Tables and Indexes into
manageable pieces.”
4 of 31
Evolution of
Partitioning in Oracle
Oracle 8 Oracle 8i Oracle 9i Oracle 9i
Release 1 Release 2
•Range •Range •Range •Range
•Hash •Hash •Hash
•Composite •List •List
*
•Range-Hash •Composite •Composite
•Range-Hash •Range-Hash
•Range-List
5 of 31
When to partition tables
• For “large” table.
Tables >= 2 Gigs *
• Performance gain outweighs the
management of partitioning.
• Archiving of data is on a schedule
and repetitive.
6 of 31
Range Partitioning
• Often used when there is a logical
range.
• Examples:
–Dates –IDs
•Start Date •Product ID
•Transaction Date •Location ID
•Close Date •UPC
•Date of Payment
7 of 31
Range Partitioning Code
CREATE TABLE PARTITION_BY_RANGE
Partition Method
( . . . Partition Key
BIRTH_MM INT NOT NULL,
BIRTH_DD INT NOT NULL,
BIRTH_YYYY INT NOT NULL)
PARTITION BY RANGE (BIRTH_YYYY, BIRTH_MM, BIRTH_DD)
(PARTITION PARTITION_01 Partition
VALUES LESS THAN (1970, 01 ,01)
TABLESPACE TS01, Definition
. . .
PARTITION PARTITION_N
VALUES LESS THAN (MAXVALUE, MAXVALUE, MAXVALUE)
TABLESPACE TS05
)
ENABLE ROW MOVEMENT;
8 of 31
Hash Partitioning
• Hashing allows for distributed data
by a hash key.
• DBAs do not have to know the
data.
• Distribution is handled by Oracle.
• Each partition can have its own
tablespace.
9 of 31
Hash Partitioning Code Hash Partitioning
Code
CREATE TABLE PARTITION_BY_HASH
(FIRST_NAME VARCHAR2(10),
Partition Method
MIDDLE_INIT VARCHAR2(1), Partition Key
LAST_NAME VARCHAR2(10),
AGE INT NOT NULL)
PARTITION BY HASH (AGE)
Partition
(PARTITION P1_AGE TABLESPACE TS01,
Definition
PARTITION P2_AGE TABLESPACE TS02,
PARTITION P3_AGE TABLESPACE TS03,
PARTITION P4_AGE TABLESPACE TS04)
ENABLE ROW MOVEMENT;
10 of 31
List Partitioning
• Added in Oracle 9.1
• In 9.2 the “DEFAULT” partition
method was added.
• Allows DBAs to explicitly define
what is in a partition.
• Example
– States into a Region
– Departments into a Division
11 of 31
List Partitioning Code List Partitioning Code
CREATE TABLE PARTITION_BY_LIST Partition Method
(DEPTID NUMBER, Partition Key
DEPTNAME VARCHAR2(15),
STATE VARCHAR2(2))
Partition
PARTITION BY LIST (STATE) Definition
(PARTITION DEPTS_IN_NORTH VALUES ('AK')
TABLESPACE TS01,
. . .
PARTITION DEPTS_WITH_NO_REGION VALUES
(DEFAULT)
TABLESPACE TS05)
ENABLE ROW MOVEMENT;
12 of 31
Composite Range-Hash
• Partition by Range
• Stored by a Hash algorithm
• DBAs can focus on both the ease
of Range Partitioning and get the
benefits of Hash Partitioning
• Logically divide the data and let
Oracle determine where to store.
13 of 31
Composite Range-Hash Code Composite Range-Hash Code
CREATE TABLE PARTITION_BY_RANGE_HASH
( FIRST_NAME VARCHAR2(10),
MIDDLE_INIT VARCHAR2(1),
LAST_NAME VARCHAR2(10),
BIRTH_MM INT NOT NULL,
BIRTH_DD INT NOT NULL,
BIRTH_YYYY INT NOT NULL)
TABLESPACE USERS
14 of 31
Composite Range-Hash Code continued
PARTITION BY RANGE (BIRTH_YYYY, BIRTH_MM,
BIRTH_DD) Partition Key
Partition Method
<SUBPARTITION TEMPLATE> Partition
(PARTITION DOBS_IN_1971 Partition
VALUES LESS THAN (1972, 01 ,01),Definition
. . .
PARTITION DOBS_IN_1975 VALUES LESS THAN
(MAXVALUE, MAXVALUE, MAXVALUE))
Composite Range-Hash Code
ENABLE ROW MOVEMENT; continued
15 of 31
Composite Range-Hash Code continued
Subpartition Subpartition
Method Key
SUBPARTITION BY HASH(FIRST_NAME, MIDDLE_INIT,
LAST_NAME)
SUBPARTITION TEMPLATE( Subpartition
SUBPARTITION SP1 TABLESPACE TS01, Name
SUBPARTITION SP2 TABLESPACE TS02,
SUBPARTITION SP3 TABLESPACE TS03,
SUBPARTITION SP4 TABLESPACE TS04,
SUBPARTITION SP5 TABLESPACE TS05)
Composite Range-Hash Code
continued
16 of 31
Composite Range-List
• Similar to Range-Hash partitioning.
• Subpartition is by List method.
• Allows for greater control by the
DBAs.
• Proper use of Range-List must be
carefully thought out.
17 of 31
Composite Range-List Code
CREATE TABLE PARTITION_BY_RANGE_LIST
( FIRST_NAME VARCHAR2(10),
MIDDLE_INIT VARCHAR2(1),
LAST_NAME VARCHAR2(10),
BIRTH_MM INT NOT NULL,
BIRTH_DD INT NOT NULL,
BIRTH_YYYY INT NOT NULL,
STATE VARCHAR2(2) NOT NULL)
TABLESPACE USERS
Composite Range-List Code
18 of 31
Composite Range-List Code continued
PARTITION BY RANGE (BIRTH_YYYY, BIRTH_MM,
BIRTH_DD)
Partition Key
Partition Method
<SUBPARTITION TEMPLATE> Partition
(PARTITION DOBS_IN_1971 Partition
VALUES LESS THAN (1972, 01 ,01),Definition
. . .
PARTITION DOBS_IN_1975 VALUES LESS THAN
(MAXVALUE, MAXVALUE, MAXVALUE))
Composite Range-List Code
ENABLE ROW MOVEMENT; continued
19 of 31
Composite Range-List Code continued
Subpartition Method Subpartition Key
SUBPARTITION BY LIST (STATE)
SUBPARTITION TEMPLATE
Subpartition
(SUBPARTITION IN_NORTH VALUES
Name
('AK') TABLESPACE TS01,
SUBPARTITION IN_EAST VALUES
('NY', 'NJ', 'VA', 'CT') TABLESPACE TS02,
. . .
SUBPARTITION NO_STATE VALUES
(DEFAULT) TABLESPACE TS05)
Composite Range-List Code
continued
20 of 31
Globally Partitioned Indexes
• Two types of Globally Partition Indexes.
– Non-Partitioned
– Partitioned
• Globally Non-Partitioned Indexes are
“regular” indexes used in OLTP.
• Globally Partitioned Indexes are similar
in syntax to Range partitioned tables.
21 of 31
Globally Partitioned Index Code
CREATE INDEX PARTITION_BY_RANGE_GPI Index
ON PARTITION_BY_RANGE (BIRTH_YYYY) Method
GLOBAL PARTITION BY RANGE (BIRTH_YYYY)
(PARTITION DOBS_IN_1971_OR_B4 Index
VALUES LESS THAN (1972) Partition
TABLESPACE ITS01,
PARTITION DOBS_IN_1972_GPI
VALUES LESS THAN (1973)
TABLESPACE ITS02,
. . .
PARTITION DOBS_IN_1975_OR_L8R Index
VALUES LESS THAN (MAXVALUE) Partition
TABLESPACE ITS05); Globally Partitioned Index Code
22 of 31
Locally Partitioned Indexes
• Oracle manages the rebuild of LPI
• Extra time should be allocated for
– Range-Hash
– Range-List
• LPI can “point” to partition or
subpartition level.
• No SUBPARTITION TEMPLATE
23 of 31
Locally Partitioned Index Code
(LPI at Partition Level)
CREATE INDEX PARTITION_BY_RANGE_HASH_LIP
ON
PARTITION_BY_RANGE_HASH (LAST_NAME)
LOCAL Index
Method
( PARTITION <PARTITION_NAME01>
TABLESPACE ITS01, Index
Partition
...
PARTITION <PARTITION_NAMEN>
Locally Partitioned Index Code –
TABLESPACE ITSN); Partition Level
24 of 31
Locally Partitioned Index Code
Continued
(LPI at Subpartition Level) Index
Method
CREATE INDEX <INDEX_NAME>
ON <TABLE_NAME> (<COLUMNS>) LOCAL
(PARTITION <PARTITION_NAME> TABLESPACE ITS0N
( SUBPARTITION <SUBPARTITION_NAME>
TABLESPACE ITS01 ,
Index
...
Partition
SUBPARTITION <SUBPARTITION_NAME>
TABLESPACE ITS0N
), Index
Locally Partitioned Index Code –
... Subpartition Level Subpartition
25 of 31
Locally Partitioned Index Code
Continued
(LPI at Subpartition Level)
(PARTITION <PARTITION_NAME> TABLESPACE ITS0N
( SUBPARTITION <SUBPARTITION_NAME>
TABLESPACE ITS01 , Index
... Partition
SUBPARTITION <SUBPARTITION_NAME>
TABLESPACE ITS0N
Index
) Subpartition
); Locally Partitioned Index Code –
Subpartition Level
26 of 31
Bringing It All Together
• 5 table partition methods
– Range, Hash, List, Range-Hash, Range-List
• 3 index partition methods
– Global Non-partition, Global partition,
Locally partition
• Guidelines
– Is the table the “right” size?
– How volatile is the data?
– What are your maintenance considerations?
27 of 31
Other Sources Of Information
• Oracle9i Database Concepts Release 2
(9.2) Part Number A96524-01
Chapter 11 Partitioned Tables and
Indexes
• Oracle9i Database Administrator's Guide
Release 2 (9.2) Part Number
A96521-01
Chapter 17 Managing Partitioned Tables
and Indexes*
28 of 31
Summary
• Basics of partitioning
– Definition, Evolution & When to partition
• Table partitioning methods
– Range, Hash, List, Range-Hash, Range-List
• Index partitioning methods
– Global Nonpartition, Global Partition, Locally
Partition
• Wrapped It Up
– Bringing it all together, Other Sources Of
Information
29 of 31
Question and Answer
Question
and
Answer
30 of 31
Ending Slide
Learn How To Partition
In Oracle 9i Release 2
Reference Number: #31316
By
Eric Yen
System Consultant
Quest Software
31 of 31