Oracle数据库中分区表的操做方法

1、为何要作分区表?sql

当数据量很是大,好比几百GB或是到T的时候。那查询的速度可想而知,Oracle提供了对表和索引进行分区的技术,以改善大型应用系统的性能。 数据库

使用分区的优势: 
  ·加强可用性:若是表的某个分区出现故障,表在其余分区的数据仍然可用; 
  ·维护方便:若是表的某个分区出现故障,须要修复数据,只修复该分区便可; 
  ·均衡I/O:能够把不一样的分区映射到磁盘以平衡I/O,改善整个系统性能; 
  ·改善查询性能:对分区对象的查询能够仅搜索本身关心的分区,提升检索速度。
  Oracle数据库提供对表或索引的分区方法有三种: 
  ·范围分区   ·Hash分区(散列分区)   ·复合分区 less

2、下边分别对三种分区方法做操做
性能

    为了方便,先创建三个表空间测试

create tablespace test1 datafile 'd:/分区test/test1.dnf' size 50M;
create tablespace test2 datafile 'd:/分区test/test2.dnf' size 50M;
create tablespace test3 datafile 'd:/分区test/test3.dnf' size 50M;

 1.范围分区
spa

1.1根据序号进行分区建表code

SQL> create table fenqutest(
  2  id number,
  3  name varchar2(50)
  4  )
  5  partition by range(id)
  6  (partition part1 values less than(5) tablespace test1,
  7  partition part2 values less than(10) tablespace test2,
  8  partition part3 values less than(maxvalue) tablespace test3);

这是我本身的作的小测试,很简写。对象

那么当表建完了,数据也添加好了,怎么来查看某个数据在哪张表里呢?索引

很简单:select * from fenqutest partition(part1);hash

1.2根据日期进行分区建表

SQL> create table fenqutest(
    id number,
    time_test date,
    name varchar2(50)
    )
    partition by range(time_test)
    (partition part1 values less than(to_date(’2011-02-27’,’yyyy-mm-dd’)) tablespace test1,
    partition part2 values less than(to_date(’2014-02-28’,’yyyy-mm-dd’)) tablespace test2,
    partition part3 values less than(maxvalue) tablespace test3);

固然你也能够根据别的来分区

2.Hash分区(散列分区)

散列分区为经过指定分区编号来均匀分布数据的一种分区类型,由于经过在I/O设备上进行散列分区,使得这些分区大小一致

SQL> create table fenqutest(
    id number,
    time_test date,
    name varchar2(50)
    )
    partition by hash(id)
    (partition part1 tablespace test1,
    partition part2 tablespace test2,
    partition part3 tablespace test3);

3.复合分区

有时候咱们须要根据范围分区后,每一个分区内的数据再散列地分布在几个表空间中,这样咱们就要使用复合分区。复合分区是先使用范围分区,而后在每一个分区内再使用散列分区的一种分区方法

SQL> create table fenqutest(
    id number,
    time_test date,
    name varchar2(50)
    )
    partition by range(time_test) subpartition by hash(id)
    subpartitions 3 store in (test1,test2,test3) 
   (partition part1 values less than(to_date(’2011-02-27’,’yyyy-mm-dd’)) tablespace test1,
    partition part2 values less than(to_date(’2014-02-28’,’yyyy-mm-dd’)) tablespace test2,
    partition part3 values less than(maxvalue) tablespace test3);
相关文章
相关标签/搜索