05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 13 ■ PARTITIONING 567<br />

Table Partitioning Schemes<br />

There are currently four methods by which you can partition tables in <strong>Oracle</strong>:<br />

• Range partitioning: You may specify ranges of data that should be stored together. For<br />

example, everything that has a timestamp within the month of Jan-2005 will be stored<br />

in partition 1, everything with a timestamp within Feb-2005 will be stored in partition 2,<br />

<strong>and</strong> so on. This is probably the most commonly used partitioning mechanism in <strong>Oracle</strong>.<br />

• Hash partitioning: You saw this in the first example in this chapter. A column (or<br />

columns) has a hash function applied to it, <strong>and</strong> the row will be placed into a partition<br />

according to the value of this hash.<br />

• List partitioning: You specify a discrete set of values, which determines the data that<br />

should be stored together. For example, you could specify that rows with a STATUS<br />

column value in ( 'A', 'M', 'Z' ) go into partition 1, those with a STATUS value in<br />

( 'D', 'P', 'Q' ) go into partition 2, <strong>and</strong> so on.<br />

• Composite partitioning: This is a combination of range <strong>and</strong> hash or range <strong>and</strong> list. It<br />

allows you to first apply range partitioning to some data, <strong>and</strong> then within that range<br />

have the final partition be chosen by hash or list.<br />

In the following sections, we’ll look at the benefits of each type of partitioning <strong>and</strong> at the<br />

differences between them. We’ll also look at when to apply which schemes to different application<br />

types. This section is not intended to present a comprehensive demonstration of the<br />

syntax of partitioning <strong>and</strong> all of the available options. Rather, the examples are simple <strong>and</strong><br />

illustrative, <strong>and</strong> designed to give you an overview of how partitioning works <strong>and</strong> how the different<br />

types of partitioning are designed to function.<br />

■Note For full details on partitioning syntax, I refer you to either the <strong>Oracle</strong> SQL Reference Guide or to the<br />

<strong>Oracle</strong> Administrator’s Guide. Additionally, the <strong>Oracle</strong> Data Warehousing Guide is an excellent source of information<br />

on the partitioning options <strong>and</strong> is a must-read for anyone planning to implement partitioning.<br />

Range Partitioning<br />

The first type we will look at is a range partitioned table. The following CREATE TABLE statement<br />

creates a range partitioned table using the column RANGE_KEY_COLUMN. All data with a RANGE_<br />

KEY_COLUMN strictly less than 01-JAN-2005 will be placed into the partition PART_1, <strong>and</strong> all data<br />

with a value strictly less than 01-JAN-2006 will go into partition PART_2. Any data not satisfying<br />

either of those conditions (e.g., a row with a RANGE_KEY_COLUMN value of 01-JAN-2007) will fail<br />

upon insertion, as it cannot be mapped to a partition:<br />

ops$tkyte@ORA10GR1> CREATE TABLE range_example<br />

2 ( range_key_column date ,<br />

3 data varchar2(20)<br />

4 )<br />

5 PARTITION BY RANGE (range_key_column)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!