大規模な表や索引をパーティションという単位で分割して管理しやすいようにしいます。 これは、ファイルシステムのボリューム機能と同じようなものです。
LONGデータ型、LONG RAW型データ以外の表はパーティションに分割できます。また最大64,000の分割が可能です。
索引構成表はレンジ・パーティション、ハッシュ・パーティション化がサポートされています。
2GB以上の表
-- range_partition.sql
-- auhtor satoshi okita
-- since 2004/04/08 12:10:00
-- -------------------
--
-- RANGE PARTITIONING
--
drop table sales_range cascade constraints;
create table sales_range
( salesman_id number(5),
salesman_name varchar2(30),
sales_amount number(10),
sales_date date)
PARTITION BY RANGE(sales_date)
(
PARTITION sales_Q1_2004 values less than (to_date('2004/04/01',
'YYYY/MM/DD')),
PARTITION sales_Q2_2004 values less than (to_date('2004/07/01',
'YYYY/MM/DD')),
PARTITION sales_Q3_2004 values less than (to_date('2004/10/01',
'YYYY/MM/DD')),
PARTITION sales_Q4_2004 values less than (to_date('2005/01/01',
'YYYY/MM/DD'))
);
--
-- LIST PARTITIONING
--
drop table sales_list cascade constraints;
create table sales_list (
salesman_id number(5),
salesman_name varchar2(30),
sales_state varchar2(20),
sales_amount number(10),
sales_date date
)
PARTITION BY LIST(sales_state)
(
PARTITION sales_asia values ('asia'),
PARTITION sales_us values ('usa','kanada'),
PARTITION sales_euro values ('eu'),
PARTITION sales_other values (DEFAULT)
);
--
-- HASH PARTITIONING
--
drop table sales_hash2 cascade constraints;
drop tablespace hash_p1 including contents and datafiles cascade
constraints;
drop tablespace hash_p2 including contents and datafiles cascade
constraints;
drop tablespace hash_p3 including contents and datafiles cascade
constraints;
drop tablespace hash_p4 including contents and datafiles cascade
constraints;
--
create tablespace hash_p1 datafile
'/opt/app/oracle/oradata/test/partition_01.dbf' size 20m autoextend on;
create tablespace hash_p2 datafile
'/opt/app/oracle/oradata/test/user/partition_02.dbf' size 20m
autoextend on;
create tablespace hash_p3 datafile
'/opt/app/oracle/oradata/test/user/partition_03.dbf' size 20m
autoextend on;
create tablespace hash_p4 datafile
'/opt/app/oracle/oradata/test/user/partition_04.dbf' size 20m
autoextend on;
create table sales_hash
( salesman_id number(5),
salesman_name varchar2(30),
sales_amount number(10),
week_no number(2))
PARTITION BY HASH(salesman_id)
PARTITIONS 4
STORE IN (hash_p1, hash_p2, hash_p3, hash_p4);
/
パーティション索引には、大きく分けてローカルとグローバルがあります。 ローカルの場合は、パーティション表と対となる索引を作成します。これは明示的に登録や削除 を行うものではなく、パーティション表を作成した際に自動的に作られるものです。 グローバルは、ある項目ごとにパーティション索引を作成することです。 普通のテーブルでも、何らかの索引が必要になる場合がありますが、 これも同じようなものです。
-- partition_idx.sql
--
--
drop table employee cascade constraints;
create table employee (
employee_id number(4) not
null,
last_name varchar2(10),
department_id number(2)
) PARTITION BY RANGE (department_id) (
PARTITION employee_part1 values less than (11) tablespace users,
PARTITION employee_part2 values less than (21) tablespace users,
PARTITION employee_part3 values less than (31) tablespace users
);
-- local index
--create index employee_local_idx on employee(employee_id) local;
-- global index
--create index employee_global_idx on employee(employee_id);
--
-- GROBAL PARTIION INDEX
--
create index employee_global_part_idx on employee(employee_id)
GLOBAL PARTITION BY RANGE(employee_id) (
PARTITION p1 values less than (5000),
PARTITION p2 values less than (MAXVALUE)
);
パーティション表やパーティション索引には、いくつか用語が出てきますので今後、インターネットの検索や 調べていくためのキーワードとして記述しておきます。
Oracle9i データベース概要 リリース2(9.2).pdf 11章 パーティション表とパーティション索引