Sunteți pe pagina 1din 24

Oracle Partitioning -- A Primer

1 1

MyOnlineITCourses.com MyOnlineITCourses.com

Partitioning
Partitioning is the ability of the database to take very large tables or indexes and
physically smaller

break them into

manageable

pieces.

2 2

MyOnlineITCourses.com MyOnlineITCourses.com

Partitioned

VS

Non Partitioned Table

3 3

MyOnlineITCourses.com MyOnlineITCourses.com

Partitions - Benefits
ORDERS ORDERS ORDERS

USA

EUROPE

JAN FEB
Large Table Partition

JAN FEB
Composite Partition

Difficult to Manage

Divide and Conquer


Easier to Manage Improve Performance

Better Performance
More flexibility to match business needs

Transparent to applications
4 4
MyOnlineITCourses.com MyOnlineITCourses.com

Partitioning - Benefits
Queries will access only those relevant partitions
Faster

An entire partition can be exported Exported partition can be deleted from Cheaper database Partition Maintenance is simpler when compared to a large un-partitioned table Flexible Partition backup/restoration is easier

5 5

MyOnlineITCourses.com MyOnlineITCourses.com

When To Partition - Table

Here are some suggestions for when to partition a table:

Tables greater than 2 GB should always be considered as candidates for partitioning.

Tables containing historical data, in which new data is added into the newest partition. A typical example is a historical table where only the current month's data is updatable and the other 11 months are read only. When the contents of a table need to be distributed across different types of storage devices.

6 6

MyOnlineITCourses.com MyOnlineITCourses.com

Partition Strategies

7 7

MyOnlineITCourses.com MyOnlineITCourses.com

Partition Type .. (Examples)

8 8

MyOnlineITCourses.com MyOnlineITCourses.com

Range Partitioned Tables


Data distribution is based on range of values Data distribution is continuous Definition Best performance when data distribution is even on the partition key. Knowledge of data is critical before choosing this

Example

Date as partitioning key Jan 2011, Feb 2011, Mar 2011 so on..

Department code as partitioning key Values <= 30, Values > 30

9 9

MyOnlineITCourses.com MyOnlineITCourses.com

DDL Example
CREATE TABLE DEPT (

DEPTNO NUMBER (2),


DEPT_NAME VARCHAR2 (30)) PARTITION BY RANGE (DEPTNO) ( PARTITION D1 VALUES LESS THAN (10) TABLESPACE DEPT1, PARTITION D2 VALUES LESS THAN (20) TABLESPACE DEPT2, PARTITION D1 VALUES LESS THAN (MAXVALUE) TABLESPACE DEPT3 )

10 10

MyOnlineITCourses.com MyOnlineITCourses.com

Range Partition (Multi column)


Defined on two or more columns of the table Multi Column Range Partition

Advantages

Enhances Query performance if searched on partition key Improves the Manageability of partitions

11 11

MyOnlineITCourses.com MyOnlineITCourses.com

When to use Range Partition


Very large tables being scanned on a range predicate like Order-Date Very less time for administrative operations like backup on large tables

Need to maintain rolling window of data

12 12

MyOnlineITCourses.com MyOnlineITCourses.com

Hash Partitioning
Specify the number of partitions Oracle database inserts rows based on hash value of partition key Specify storage for the entire table and the tablespace for partitions

Always Define 2n Partitions

Partition Key

13 13

MyOnlineITCourses.com MyOnlineITCourses.com

Storage

Hash Partition Example


Hash-partitioned table that splits the table into four parts based on the hash of the partition key, acct_no.

CREATE TABLE CUST_SALES_HASH ( ACCT_NO NUMBER (5), CUST_NAME CHAR (30))

PARTITION BY HASH (ACCT_NO) PARTITIONS 4


STORE IN (USERS1, USERS2, USERS3, USERS4);

14 14

MyOnlineITCourses.com MyOnlineITCourses.com

When to use Hash Partition


Improve Manageability/availability of Large tables Avoid data skew in partitions

Maximize I/0 throughput

15 15

MyOnlineITCourses.com MyOnlineITCourses.com

List Partitioning
Segmenting data with a list of values

Definition

Flexible means of partitioning where data is better understood Similar to Range Partitioning, but without any max value

CREATE TABLE DEPT_PART (DEPTNO NUMBER (2),DNAME VARCHAR2 (14),LOC VARCHAR2 (13)) PARTITION BY LIST (DNAME) (PARTITION D1_EAST VALUES (NEW YORK), PARTITION D2_WEST VALUES (SAN FRANCISCO, LOS ANGELES), PARTITION D3_SOUTH VALUES (ATLANTA,DALLAS,HOUSTON),

Example

PARTITION D4_NORTH VALUES (CHICAGO,DETROIT));

16 16

MyOnlineITCourses.com MyOnlineITCourses.com

Range ,List , Hash Partitions

17 17

MyOnlineITCourses.com MyOnlineITCourses.com

Composite Partitioning

Data is Partitioned along two dimensions

A distinct value pair for the two dimensions uniquely determines the target partition

Composite Partitioning is complementary to multi column range partition

18 18

MyOnlineITCourses.com MyOnlineITCourses.com

Composite Partitioning Strategies


New 11g Strategy List Range Range - Range List - Hash Use Case Geography Time Ship Date Order Date Geography OrderID

List - List

Geography Product

19 19

MyOnlineITCourses.com MyOnlineITCourses.com

Range List Partitioning

20 20

MyOnlineITCourses.com MyOnlineITCourses.com

Composite Partitioning Range - Range Table SALES


RANGE(order_date)-RANGE(ship_date) ship_date

All records with


Jan 2006 Feb 2006

...
...

...
...

order_date in March 2006 AND ship_date in May 2006

...
May May 2006

... ... ...


...
Mar Mar2006 2006 Jan 2007

...
Jan 2006 Feb 2006 order_date

21 21

MyOnlineITCourses.com MyOnlineITCourses.com

Would like to learn more about oracle ???

22 22

MyOnlineITCourses.com MyOnlineITCourses.com

www.MyOnlineITCourses.com

We give quality online trainings by IT Professionals for


Oracle SQL , PL/SQL Oracle DBA Oracle Performance Tuning Data Modelling with Erwin Tool

To get more details contact us


info@myonlineitcourses.com +91 991 2323 000 www.Facebook.com/MyOnlineITCourses


MyOnlineITCourses.com MyOnlineITCourses.com

23 23

24 24

MyOnlineITCourses.com MyOnlineITCourses.com

S-ar putea să vă placă și