You are on page 1of 5

Partitioning in Oracle. What? Why? When? Who? Where? How?

Business applications are growing at a faster rate than salaries, and so is the data supporting them, especially e-business applications where the data growth has been around 20-30 percent or more annually. Oracle came up with the idea of Partitioning the Tables. Yes ! The name sounds right “Partitioning”, the literal meaning of Partitioning is “The Act of dividing something into parts” and in our case that „something‟ is nothing but…? You guessed it right! Data. Partitioning enables tables and indexes or index-organized tables to be subdivided into smaller manageable pieces and these each small piece is called a "partition". From an "Application Development" perspective, there is no difference between a partitioned and a non-partitioned table. The application need not be modified to access a partitioned table if that application was initially written on a non partitioned tables. So now you know partitioning in oracle now the only thing that yo u need to know is little bit of syntax and that‟s it, and you are a partitioning guru. Oracle introduced partitioning with 8.0. With this version only, " Range Partitioning" was supported. I will come to details later about what that means. Then with Oracle 8i " Hash and Composite Partitioning" was also introduced and with 9i " List Partitioning", it was introduced with lots of other features with each upgrade. Each method of partitioning has its own advantages and disadvantages and the decision which one to use will depend on the data and type of application. Also one can MODIFY , RENAME, MOVE, ADD, DROP, TRUNCATE, SPLIT partitions. We will go thru the details now. Advantages of using Partition’s in Table 1. 2. 3. 4. 5. 6. 7. Smaller and more manageable pieces of data ( Partitions ) Reduced recovery time Failure impact is less import / export can be done at the " Partition Level". Faster access of data Partitions work independent of the other partitions. Very easy to use

Types of Partitioning Methods 1. RANGE Partitioning This type of partitioning creates partitions based on the " Range of Column" values. Each partition is defined by a " Partition Bound" (non inclusive ) that basically limits the scope of partition. Most commonly used values for " Range Partition" is the Date field in a table. Lets say we have a table SAMPLE_ORDERS and it has a field ORDER_DATE. Also, lets say we

„DD-MON-YYYY‟). TO_DATE(„01-JAN-2000‟. The first partition will be the one with the lowest bound and the last one will be the Partition with the highest bound. TO_DATE(„01-JUL-2000‟. CUST_NUM NUMBER. TO_DATE(„01-APR-2000‟. „DD-MON-YYYY‟). TO_DATE(„01-APR-1999‟. ORDER_ZIP_CODE) PARTITION BY HASH (ORDER_ZIP_CODE) . Lets take one example. TO_DATE(„01-JAN-2001‟. are partitions based of a Hash value found in the value of the column. we can create partitions by date for. TO_DATE(„01-OCT-1999‟. that is used for partitioning. TOTAL_PRICE NUMBER. TOTAL_TAX NUMBER. TOTAL_PRICE NUMBER. „DD-MON-YYYY‟). TO_DATE(„01-JUL-1999‟. „DD-MON-YYYY‟). TOTAL_SHIPPING NUMBER. lets say. ORDER_DATE DATE. „DD-MON-YYYY‟) the above example basically created 8 partitions on the SAMPLE_ORDERS Table all these partitions correspond to one quarter. This is example of the syntax needed for creating a RANGE PARTITION. 2. every quarter. So if we have a query that want to look at the Data of first quarter of 1999 then instead of going through the complete data it will directly go to the Partition of first quarter 1999. HASH Partitioning Under this type of partitioning the records in a table. „DD-MON-YYYY‟). „DD-MON-YYYY‟). "Hash Partitioning" does not have any logical meaning to the partitions as do the range partitioning. CREATE TABLE SAMPLE_ORDERS (ORDER_NUMBER NUMBER. ORDER_DATE DATE. So Every Quarter Data becomes a partition in the SAMPLE_ORDER table. Then. Partition SO99Q1 will contain the orders for only first quarter of 1999. CUST_NUM NUMBER.have 5 years of history in this table. „DD-MON-YYYY‟). TOTAL_TAX NUMBER. TO_DATE(„01-OCT-2000‟. TOTAL_SHIPPING NUMBER) PARTITION BY RANGE(ORDER_DATE) ( PARTITION SO99Q1 VALUES LESS THAN PARTITION SO99Q2 VALUES LESS THAN PARTITION SO99Q3 VALUES LESS THAN PARTITION SO99Q4 VALUES LESS THAN PARTITION SO00Q1 VALUES LESS THAN PARTITION SO00Q2 VALUES LESS THAN PARTITION SO00Q3 VALUES LESS THAN PARTITION SO00Q4 VALUES LESS THAN ) . CREATE TABLE SAMPLE_ORDERS (ORDER_NUMBER NUMBER.

„Employees‟ . TOTAL_TAX NUMBER. represent a logical subset of the data. . PARTITION SHIP_TO_MICHIGAN VALUES („MI‟) TABLESPACE TS05) ENABLE ROW MOVEMENT. „European‟ then a List Partition can be created for individual or a group of communities lets say „American-partition‟ will have all the records having the community as „American‟ Lets take one example. All sub partitions. TOTAL_PRICE NUMBER. „Asian‟ . PARTITION SHIP_TO_MASACHUSETTES VALUES („MA‟) TABLESPACE TS04. „American‟. SHIP_TO_STATE) PARTITION BY LIST (SHIP_TO_STATE) (PARTITION SHIP_TO_ARIZONA VALUES („AZ‟) TABLESPACE TS01. CUST_NUM NUMBER. PARTITION SHIP_TO_CALIFORNIA VALUES („CA‟) TABLESPACE TS02. we will modify the same example. CUST_NUM NUMBER. The above example creates List partition based on the SHIP_TO_STATE each partition allocated to different table spaces. PARTITION P3_ZIP TABLESPACE TS03. ORDER_DATE DATE. The above example creates four hash partitions based on the zip codes from where the orders were placed. SHIP_TO_ZIP_CODE. PARTITION P4_ZIP TABLESPACE TS04) ENABLE ROW MOVEMENT. Composite Range-Hash Partitioning This is basically a combination of range and hash partitions. So basically. together. In fact. 4. the first step is that the data is divided using the range partition and then each range partitioned data is further subdivided into a hash partition using hash key values. 3. List Partitioning ( Only with 9i) Under this type of partitioning the records in a table are partitioned based on the List of values for a table with say communities column as a defining key the partitions can be made based on that say in a table we have communities like „Government‟ .(PARTITION P1_ZIP TABLESPACE TS01. TOTAL_SHIPPING NUMBER. CREATE TABLE SAMPLE_ORDERS (ORDER_NUMBER NUMBER. Lets modify the above example again: CREATE TABLE SAMPLE_ORDERS (ORDER_NUMBER NUMBER. PARTITION SHIP_TO_ILLINOIS VALUES („IL‟) TABLESPACE TS03. ORDER_DATE DATE. PARTITION P2_ZIP TABLESPACE TS02.

SHIP_TO_STATE) TABLESPACE USERS . „DD-MON-YYYY‟). PARTITION SO00Q2 VALUES LESS THAN TO_DATE(„01-JUL-2000‟. PARTITION SO00Q1 VALUES LESS THAN TO_DATE(„01-APR-2000‟. ORDER_DATE DATE. The above example shows that each range partition has been further sub-partitioned into smaller partitions based on the list value specified. PARTITION SO00Q4 VALUES LESS THAN TO_DATE(„01-JAN-2001‟. Each sub partitions individually represents logical subset of the data not like composite Range-Hash Partition. „DD-MON-YYYY‟). „DD-MON-YYYY‟). Index organized tables can be partitioned using Range or Hash Partitions Lets modify the above partition once more. 5. PARTITION SO99Q4 VALUES LESS THAN TO_DATE(„01-JAN-2000‟. „DD-MON-YYYY‟). SUBPARTITION SHIP_TO_NORTHEAST VALUES („MA‟. TOTAL_PRICE NUMBER.CUST_NAME VARCAHR2. basically first the data is divided using the Range partition and then each Range partitioned data is further subdivided into List partitions using List key values. „DD-MON-YYYY‟) ) ENABLE ROW MOVEMENT. „DD-MON-YYYY‟). TOTAL_SHIPPING NUMBER. TOTAL_TAX NUMBER. CUST_NUM NUMBER. SHIP_TO_ZIP_CODE. CREATE TABLE SAMPLE_ORDERS (ORDER_NUMBER NUMBER. PARTITION SO99Q2 VALUES LESS THAN TO_DATE(„01-JUL-1999‟. PARTITION SO00Q3 VALUES LESS THAN TO_DATE(„01-OCT-2000‟. SHIP_TO_STATE) TABLESPACE USERS PARTITION BY RANGE (ORDER_DATE) SUBPARTITION BY HASH(CUST_NAME) SUBPARTITION TEMPLATE( (SUBPARTITION SHIP_TO_ARIZONA VALUES („AZ‟) TABLESPACE TS01. This partition will be present in the main partitions by range SO99Q1 etc. „DD-MON-YYYY‟). „DD-MON-YYYY‟). „NY‟. TOTAL_PRICE NUMBER. „NJ‟) TABLESPACE TS04. SUBPARTITION SHIP_TO_CALIFORNIA VALUES („CA‟) TABLESPACE TS02. SUBPARTITION SHIP_TO_MICHIGAN VALUES („MI‟) TABLESPACE TS05) ( PARTITION SO99Q1 VALUES LESS THAN TO_DATE(„01-APR-1999‟. TOTAL_TAX NUMBER. SHIP_TO_ARIZONA is a sub-partition by a List value AZ. Composite Range-List Partitioning ( Only with 9i) This is also a combination of Range and List Partitions. PARTITION SO99Q3 VALUES LESS THAN TO_DATE(„01-OCT-1999‟. TOTAL_SHIPPING NUMBER. CUST_NAME VARCAHR2. SUBPARTITION SHIP_TO_ILLINOIS VALUES („IL‟) TABLESPACE TS03. SHIP_TO_ZIP_CODE.

„DD-MON-YYYY‟). SUBPARTITION SP4 TABLESPACE TS04. The index structure is not partitioned. PARTITION SO00Q3 VALUES LESS THAN TO_DATE(„01-OCT-2000‟. For detailed syntax and documentation refer to Oracle documentation. „DD-MON-YYYY‟) ) ENABLE ROW MOVEMENT. I hope this overview of partitioning will provide some answers to What? When? Who? Where ? Why and How? of partitioning in Oracle. c. manageability and availability of most databases. SUBPARTITION SP3 TABLESPACE TS03. „DD-MON-YYYY‟). in above example. With Oracle 9i. Global Non. But for now. Partitioning can be applied to any databases and software shops using such a great option. PARTITION SO00Q2 VALUES LESS THAN TO_DATE(„01-JUL-2000‟. b. The indexes can be: a. they can be partitioned using the "Range Partitioning" only.Partitioned Indexes This is no different than the ordinary index created on a non-partitioned table. SUBPARTITION SP2 TABLESPACE TS02. „DD-MON-YYYY‟). Partitioning greatly enhances the performance. „DD-MON-YYYY‟). „DD-MON-YYYY‟). PARTITION SO99Q3 VALUES LESS THAN TO_DATE(„01-OCT-1999‟. PARTITION SO00Q1 VALUES LESS THAN TO_DATE(„01-APR-2000‟. „DD-MON-YYYY‟). „DD-MON-YYYY‟). . PARTITION SO99Q4 VALUES LESS THAN TO_DATE(„01-JAN-2000‟. where I divided the table into partitions representing a quarter. PARTITION SO00Q4 VALUES LESS THAN TO_DATE(„01-JAN-2001‟. Each partition of a local index corresponds to one partition only. SUBPARTITION SP5 TABLESPACE TS05) ( PARTITION SO99Q1 VALUES LESS THAN TO_DATE(„01-APR-1999‟. This article does not claim to provide a full understanding or the partitioning feature in oracle. a "Global Index" can be created by using a different " Partitioning Key" and can have different number of partitions. Watch out. For example. PARTITION SO99Q2 VALUES LESS THAN TO_DATE(„01-JUL-1999‟. Global Partitioned Indexes This can be created on a partitioned or a non-partitioned tables. there is also a feature to create indexes on the partitions. So lot more to come.PARTITION BY RANGE (ORDER_DATE) SUBPARTITION BY LIST(SHIP_TO_STATE) SUBPARTITION TEMPLATE( SUBPARTITION SP1 TABLESPACE TS01. Oracle has been modifying this feature with new releases. Local indexes This is created the same manner as the index on existing partitioned table. have greatly improved the user satisfaction for there business applications.