PARTITION RANGE分区创建
2016-05-23 14:42
281 查看
Oracle是分区技术的先行者,在oracle7的时候就提出了分区技术,分区技术对于海量数据的存储和高效检索起到了不可或缺的作用。range分区是使用最多的一种分区
1.range分区简介
以列值的取值范围作为分区的划分条件
按照表的时间列对每月的数据进行分区就是一个很好的range分区的例子。
不在指定范围内的记录会被存储在maxvalue所在的分区
2.创建range分区表所需要的表空间
sec@ora10g> create tablespace tbs_part01 datafile '/oracle/oradata/ora10g/tbs_part01.dbf' size 100m;
sec@ora10g> create tablespace tbs_part02 datafile '/oracle/oradata/ora10g/tbs_part02.dbf' size 100m;
sec@ora10g> create tablespace tbs_part03 datafile '/oracle/oradata/ora10g/tbs_part03.dbf' size 100m;
sec@ora10g> create tablespace tbs_part04 datafile '/oracle/oradata/ora10g/tbs_part04.dbf' size 100m;
3.创建分区表
sec@ora10g> create table t_partition_range (id number,name varchar2(50))
partition by range(id)(
partition t_range_p1 values less than (10) tablespace tbs_part01,
partition t_range_p2 values less than (20) tablespace tbs_part02,
partition t_range_p3 values less than (30) tablespace tbs_part03,
partition t_range_pmax values less than (maxvalue) tablespace tbs_part04);
Table created.
4.查询user_part_tables视图获得“分区的表”的信息
sec@ora10g> select table_name,partitioning_type,partition_count from user_part_tables where table_name='T_PARTITION_RANGE';
TABLE_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
T_PARTITION_RANGE RANGE 4
5.查询user_tab_partitions视图获得“表的分区”信息
sec@ora10g> col TABLE_NAME for a20
sec@ora10g> col partition_name for a20
sec@ora10g> col HIGH_VALUE for a10
sec@ora10g> col TABLESPACE_NAME for a15
sec@ora10g> select table_name,partition_name,high_value,tablespace_name from user_tab_partitions where table_name='T_PARTITION_RANGE' order by partition_position;
TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
-------------------- -------------------- ---------- ---------------
T_PARTITION_RANGE T_RANGE_P1 10 TBS_PART01
T_PARTITION_RANGE T_RANGE_P2 20 TBS_PART02
T_PARTITION_RANGE T_RANGE_P3 30 TBS_PART03
T_PARTITION_RANGE T_RANGE_PMAX MAXVALUE TBS_PART04
6.创建global索引range分区
sec@ora10g> create index idx_parti_range_id on t_partition_range(id)
global partition by range(id)(
partition i_range_p1 values less than (10) tablespace tbs_part01,
partition i_range_p2 values less than (40) tablespace tbs_part02,
partition i_range_pmax values less than (maxvalue) tablespace tbs_part03);
Index created.
7.查询user_part_indexes视图获得“分区的索引”的信息
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 3
8.查询user_ind_partitions视图获得“索引的分区”信息
sec@ora10g> select index_name,partition_name,high_value,tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID I_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P2 40 TBS_PART02
IDX_PARTI_RANGE_ID I_RANGE_PMAX MAXVALUE TBS_PART03
9.创建local索引range分区
删除原有的索引
sec@ora10g> drop index idx_parti_range_id;
Index dropped.
创建
sec@ora10g> create index idx_parti_range_id on t_partition_range(id) local;
Index created.
查询local索引信息
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 4
sec@ora10g> select index_name,partition_name, high_value, tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID T_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID T_RANGE_P2 20 TBS_PART02
IDX_PARTI_RANGE_ID T_RANGE_P3 30 TBS_PART03
IDX_PARTI_RANGE_ID T_RANGE_PMAX MAXVALUE TBS_PART04
结论:local索引的分区维护完全依赖于其索引所在表
10.local索引的较高级的玩法--自定义表空间
sec@ora10g> drop index idx_parti_range_id;
Index dropped.
sec@ora10g> create index idx_parti_range_id on t_partition_range(id) local (
2 partition i_range_p1 tablespace tbs_part01,
3 partition i_range_p2 tablespace tbs_part01,
4 partition i_range_p3 tablespace tbs_part02,
5 partition i_range_pmax tablespace tbs_part02
6 );
Index created.
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 4
sec@ora10g> select index_name,partition_name, high_value, tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID I_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P2 20 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P3 30 TBS_PART02
IDX_PARTI_RANGE_ID I_RANGE_PMAX MAXVALUE TBS_PART02
比照上面的结果,这里的表空间已经调整
1.range分区简介
以列值的取值范围作为分区的划分条件
按照表的时间列对每月的数据进行分区就是一个很好的range分区的例子。
不在指定范围内的记录会被存储在maxvalue所在的分区
2.创建range分区表所需要的表空间
sec@ora10g> create tablespace tbs_part01 datafile '/oracle/oradata/ora10g/tbs_part01.dbf' size 100m;
sec@ora10g> create tablespace tbs_part02 datafile '/oracle/oradata/ora10g/tbs_part02.dbf' size 100m;
sec@ora10g> create tablespace tbs_part03 datafile '/oracle/oradata/ora10g/tbs_part03.dbf' size 100m;
sec@ora10g> create tablespace tbs_part04 datafile '/oracle/oradata/ora10g/tbs_part04.dbf' size 100m;
3.创建分区表
sec@ora10g> create table t_partition_range (id number,name varchar2(50))
partition by range(id)(
partition t_range_p1 values less than (10) tablespace tbs_part01,
partition t_range_p2 values less than (20) tablespace tbs_part02,
partition t_range_p3 values less than (30) tablespace tbs_part03,
partition t_range_pmax values less than (maxvalue) tablespace tbs_part04);
Table created.
4.查询user_part_tables视图获得“分区的表”的信息
sec@ora10g> select table_name,partitioning_type,partition_count from user_part_tables where table_name='T_PARTITION_RANGE';
TABLE_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
T_PARTITION_RANGE RANGE 4
5.查询user_tab_partitions视图获得“表的分区”信息
sec@ora10g> col TABLE_NAME for a20
sec@ora10g> col partition_name for a20
sec@ora10g> col HIGH_VALUE for a10
sec@ora10g> col TABLESPACE_NAME for a15
sec@ora10g> select table_name,partition_name,high_value,tablespace_name from user_tab_partitions where table_name='T_PARTITION_RANGE' order by partition_position;
TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
-------------------- -------------------- ---------- ---------------
T_PARTITION_RANGE T_RANGE_P1 10 TBS_PART01
T_PARTITION_RANGE T_RANGE_P2 20 TBS_PART02
T_PARTITION_RANGE T_RANGE_P3 30 TBS_PART03
T_PARTITION_RANGE T_RANGE_PMAX MAXVALUE TBS_PART04
6.创建global索引range分区
sec@ora10g> create index idx_parti_range_id on t_partition_range(id)
global partition by range(id)(
partition i_range_p1 values less than (10) tablespace tbs_part01,
partition i_range_p2 values less than (40) tablespace tbs_part02,
partition i_range_pmax values less than (maxvalue) tablespace tbs_part03);
Index created.
7.查询user_part_indexes视图获得“分区的索引”的信息
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 3
8.查询user_ind_partitions视图获得“索引的分区”信息
sec@ora10g> select index_name,partition_name,high_value,tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID I_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P2 40 TBS_PART02
IDX_PARTI_RANGE_ID I_RANGE_PMAX MAXVALUE TBS_PART03
9.创建local索引range分区
删除原有的索引
sec@ora10g> drop index idx_parti_range_id;
Index dropped.
创建
sec@ora10g> create index idx_parti_range_id on t_partition_range(id) local;
Index created.
查询local索引信息
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 4
sec@ora10g> select index_name,partition_name, high_value, tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID T_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID T_RANGE_P2 20 TBS_PART02
IDX_PARTI_RANGE_ID T_RANGE_P3 30 TBS_PART03
IDX_PARTI_RANGE_ID T_RANGE_PMAX MAXVALUE TBS_PART04
结论:local索引的分区维护完全依赖于其索引所在表
10.local索引的较高级的玩法--自定义表空间
sec@ora10g> drop index idx_parti_range_id;
Index dropped.
sec@ora10g> create index idx_parti_range_id on t_partition_range(id) local (
2 partition i_range_p1 tablespace tbs_part01,
3 partition i_range_p2 tablespace tbs_part01,
4 partition i_range_p3 tablespace tbs_part02,
5 partition i_range_pmax tablespace tbs_part02
6 );
Index created.
sec@ora10g> select index_name, partitioning_type, partition_count from user_part_indexes where index_name = 'IDX_PARTI_RANGE_ID';
INDEX_NAME PARTITI PARTITION_COUNT
------------------------------ ------- ---------------
IDX_PARTI_RANGE_ID RANGE 4
sec@ora10g> select index_name,partition_name, high_value, tablespace_name from user_ind_partitions where index_name = 'IDX_PARTI_RANGE_ID' order by partition_position;
INDEX_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ -------------------- ---------- ---------------
IDX_PARTI_RANGE_ID I_RANGE_P1 10 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P2 20 TBS_PART01
IDX_PARTI_RANGE_ID I_RANGE_P3 30 TBS_PART02
IDX_PARTI_RANGE_ID I_RANGE_PMAX MAXVALUE TBS_PART02
比照上面的结果,这里的表空间已经调整
相关文章推荐
- Android之权重
- 面试题数组篇(1)
- javascript 闭包详解+示例(一)
- 图像拼接
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- 具有自动截断功能的函数:对比:strcpy、strncpy、sprintf、snprintf在写入的数据大于缓冲区的情况下如何处理
- JBoss 性能优化(解决Jboss内存紧张的问题)
- 01章 面向对象开发方法概述
- ORA-04089: 没法对 SYS 拥有的对象创建触发器
- Android之属性动画
- Apache配置虚拟主机的三种方式
- Longest Increasing Subsequence
- iOS学习之——Notification补充
- Android自助餐之AsyncTask
- 程序人生-002-往与今
- javascript call与apply关键字的作用
- Deque 容器
- 深入理解Java之泛型
- iOS Quartz2D 渐变图形 CGGradient CGShading
- Java开发中的23种设计模式详解之二:7种结构型模式