細化解析:Oracle表分區(qū)
Oracle表分區(qū)里可以把一個表分割為多個小部分,這樣可以對Oracle表分區(qū)的查詢性能,管理表數(shù)據(jù),備份和恢復操作的性能優(yōu)化帶來改善。
Oracle表分區(qū)分為好幾種的(范圍分區(qū),散列分區(qū),子分區(qū),列表分區(qū),索引分區(qū))下面我們來慢慢介紹
現(xiàn)在我們來建立一個[范圍分區(qū)]
- create table RangeTable(
- id int primary key,
- name varchar(20),
- grade int
- )
- partition by rang(grade)
- (
- partition part1 values less then(50) tablespace Part1_tb,
- partition part2 values less then(MAXVALUE) tablespace Part2_tb
- );
如果grade的值小于50的話 就把記錄放到名為part1的分區(qū)當中,part1分區(qū)將被存儲在Part1_tb表空間中
其他的就放在part2中 MAXVALUE是Oracle的關鍵字 表示最大值
[散列分區(qū)]
- create table HashTable(
- id int primary key,
- name varchar(20),
- grade int
- )
/*有兩種方式,1就是指定分區(qū)數(shù)目和所使用的表空間,2指定以命名的分區(qū)*/
- partition by hash(grade)
- partitions 10 -- 指定分區(qū)的數(shù)目
- store in(Part1_tb,Part2_tb,Part3_tb) --如果指定的分區(qū)數(shù)目比表空間多,分區(qū)會以循環(huán)方式分配到表空間
- /*------------------------------------*/
- partition by rang(grade)--這種方式就是 指定以命名的分區(qū)
- (
- partition part1 tablespace Part1_tb,
- partition part2 tablespace Part2_tb
- );
#p#
[子分區(qū)]即是分區(qū)的分區(qū)
- create table ChildTable(
- id int primary key,
- name varchar(20),
- grade int
- )
- partition by rang(grade)
- subpartition by hash(grade)
- partitions 5
- (
- partition part1 values less then(30) tablespace Part1_tb,
- partition part2 values less then(60) tablespace Part2_tb,
- partition part3 values less then(MAXVALUE) tablespace Part3_tb
- );
[列表分區(qū)]告訴Oracle表分區(qū)所有可能的值
- create table ListTable(
- id int primary key,
- name varchar(20),
- area varchar(10)
- )
- partition by list(area)
- (
- partition part1 values('guangdong','beijing') tablespace Part1_tb,
- partition part2 values('shanghai','nanjing') tablespace Part2_tb
- );
[索引分區(qū)]索引也可以按照和表進行分區(qū)時使用的相同的值范圍來分區(qū)
- create index IndexTable_index
- on IndexTable(name)
- local
- (
- partition part1 tablespace Part1_tb,
- partition part2 tablespace Part2_tb
- )
- --local 告訴Oracle表 IndexTable的每一個分區(qū)建立一個獨立的索引
- create index IndexTable_index
- on IndexTable(name)
- global;
--global為全局索引 全局索引可以包含多個分區(qū)的值 局部索引比全局索引容易管理,而全局索引比較快
注意:不能為散列分區(qū) 或者 子分區(qū)創(chuàng)建全局索引
查詢某一個表分區(qū)
- select * from table partition(part1);
【編輯推薦】