Oracle Partitioning
In Oracle a Partition is just like the "Divide and conquer" approach, it is the way or the ability of the database to allow a DBA to physically split or break up all the very large tables, indexes and index organized tables into smaller and manageable pieces and/or segments. Each partition is known by its own characteristics. To achieve better performance is the primary objective of partitioning. It enables the database objects to be accessed and managed at a finer level of granularity.
Table types to be partitioned
The following are the table types to be partitioned:
- If the size of the table is greater than 2GB, then the partition of the same table is to be required.
- If the table is having some content and that content needs to be distributed across various type of storage devices.
- If any table in the database having historical data is also to be partitioned.
Advantages of Partition
The following are the Advantages of Partition:
- More flexible to match business needs.
- Can be stored in a different tablespace.
- Cheaper
- Faster
Types of Partition
1. RANGE PARTITIONING METHOD
The Range Partitioning method is a technique of a partition that is used when there are local ranges of data that you want to store together. Here a table is partitioned in such a way that all the data of similar type to be stored is in the same partition. In a Range Partition each partition is based on the range of the partition key values.
Example: Date range.
Example
CREATE TABLE Students_range
(
Student_id NUMBER(10),
Student_name VARCHAR2(20),
Fee_amount NUMBER(15),
Admission_date DATE
)
PARTITION BY RANGE(Addmission_date)
(
PARTITION Students_Jan2013 VALUES LESS THAN(TO_DATE('01/02/2013','DD/MM/YYYY')),
PARTITION Students_Feb2013 VALUES LESS THAN(TO_DATE('01/03/2013','DD/MM/YYYY')),
PARTITION Students_Mar2013 VALUES LESS THAN(TO_DATE('01/04/2013','DD/MM/YYYY')),
PARTITION Students_Apr2013 VALUES LESS THAN(TO_DATE('01/05/2013','DD/MM/YYYY'))
);
2. HASH PARTITIONING METHOD
The Hash Partitioning method is much better than the Range Partitioning, since it enables the easy partitioning of data where a hash key is used to distribute rows evenly across the various partitions.
Example: Order_Number, Order_id.
Example
CREATE TABLE Employee
(
Emp_Id number(10),
Emp_name varchar2(20),
Contact_num Number,
Address Varchar2(50),
Salary Number
)
PARTITION BY HASH(Emp_Id)
(
PARTITION Emp01 tablespace Employee1,
PARTITION Emp02 tablespace Employee2,
PARTITION Emp03 tablespace Employee3,
PARTITION Emp04 tablespace Employee4
PARTITION Emp05 tablespace Employee5
PARTITION Emp06 tablespace Employee6
);
Or
CREATE TABLE Employee
(
Emp_Id number(4),
Emp_name varchar2(30),
Contact_num Number,
Address Varchar2(50),
Salary Number
)
PARTITION BY HASH(Emp_Id)
PARTITIONS 6
STORE IN (Empts1, Empts2, Empts3, Empts4, Empts5, Empts6);
3. COMPOSITE PARTITIONING METHOD
The Composite Partitioning method is a combination of various partitioning techniques like:
- Range-hash
- Range-list
- List-hash
- Interval-hash
- Interval-range and so on.
Where partitions are based on columns to specify range. Using Composite Partitioning will allow queries to benefit from table partitioning. It supports historical operations.
Example
CREATE TABLE Customers_composite
(
Customer_id NUMBER(10),
Customer_name VARCHAR2(20),
Item_Price NUMBER(15),
Purchase_date DATE
)
PARTITION BY RANGE(Purchase_date)
SUBPARTITION BY HASH(Customer_id)
SUBPARTITION TEMPLATE
(
SUBPARTITION SubPart1 TABLESPACE ts1,
SUBPARTITION SubPart2 TABLESPACE ts2,
SUBPARTITION SubPart3 TABLESPACE ts3,
SUBPARTITION SubPart4 TABLESPACE ts4
)
(
PARTITION Customers_Jan2013 VALUES LESS THAN(TO_DATE('01/02/2000','DD/MM/YYYY'))
PARTITION Customers_Feb2013 VALUES LESS THAN(TO_DATE('01/03/2000','DD/MM/YYYY'))
PARTITION Customers_Mar2013 VALUES LESS THAN(TO_DATE('01/04/2000','DD/MM/YYYY'))

Join the conversation! Your thoughts help the community grow.