我們知道在資料庫中,當一張表的資料量增多時,資料的查詢就會變慢,從而影響應用程式的效能。這時我們應該考慮將表分割槽,表分割槽後在邏輯上仍然屬於一張表,只是在物理上儲存在多個檔案中。
範圍分割槽將資料基於範圍對映到每乙個分割槽,這個範圍是你在建立分割槽時指定的分割槽鍵決定的。這種分割槽方式是最為常用的,並且分割槽鍵經常採用日期。舉個例子:你可能會將銷售資料按照月份進行分割槽。
-- 按行分割槽
create
table student
( id number not
null
primary
key,
name varchar2(30)
notnull
, *** char(1
)not
null
, phonevarchar2(15)
notnull
, emailvarchar2(80)
,status
char(1
))partition
by range (id)
(partition student_part1 values less than (
100000
)tablespace test_space,
partition student_part2 values less than (
200000
)tablespace test_space
)-- 按時間分割槽
create
table order_activities
( order_id number(7)
notnull
, order_date date
, total_amount number,
custotmer_id number(7)
, paid char(1
))partition
by range (order_date)
(partition p1 values less than (to_date(
'2014-10-1'
,'yyyy-mm-dd'))
tablespace test_space ,
partition p2 values less than (to_date(
'2015-10-1'
,'yyyy-mm-dd'))
tablespace test_space,
partition p3 values less than (to_date(
'2016-10-1'
,'yyyy-mm-dd'))
tablespace test_space)
這類分割槽是在列值上使用hash演算法,以確定將行放入哪個分割槽中。當列的值沒有合適的條件時,建議使用雜湊分割槽。雜湊分割槽為通過指定分割槽編號來均勻分布資料的一種分割槽型別,因為通過在i/o裝置上進行雜湊分割槽,使得這些分割槽大小一致
create
table hash_table
( col number(8)
, inf varchar2(
100)
)partition
byhash
(col)
(partition part01 tablespace test_space,
partition part02 tablespace test_space,
partition part03 tablespace test_space
)
該分割槽的特點是某列的值只有幾個,基於這樣的特點我們可以採用列表分割槽
create
table student
( id number not
null
primary
key,
name varchar2(30)
notnull
, *** char(1
)not
null
, phonevarchar2(15)
notnull
, emailvarchar2(80)
,status
char(1
))partition
by range (id)
(partition student_0 values(0
)tablespace test_space,
partition student_1 values(1
)tablespace test_space
)
採用以上多種分割槽方式的組合
-- 這種分割槽是基於範圍分割槽和雜湊分割槽,表首先按某列進行範圍分割槽,然後再按某列進行雜湊分割槽
create
table hashtable (
transaction_id number primary
key,
item_id number(8)
notnull
, item_description varchar2(
300)
, transaction_date date
)partition
by range (transaction_date)
subpartition by
hash
(transaction_id)
(partition part_01 values less than (to_date(
'2014-10-1'
,'yyyy-mm-dd'))
,partition part_02 values less than (to_date(
'2015-10-1'
,'yyyy-mm-dd'))
,partition part_03 values less than (maxvalue)
);
Oracle分割槽表
1 範圍分割槽 range create table range part tab id number,deal date date,area code number,contents varchar2 4000 partition by range deal date partition p201...
oracle表分割槽設計 ORACLE 分割槽表的設計
分割槽表的概念 分割槽致力於解決支援極大表和索引的關鍵問題。它採用他們分解成較小和易於管理的稱為分割槽的片 piece 的方法。一旦分割槽被定義,sql語句就可以訪問的操作某乙個分割槽而不是整個表,因而提高管理的效率。分割槽對於資料倉儲應用程式非常有效,因為他們常常儲存和分析巨量的歷史資料。分割槽表...
oracle表分割槽設計 ORACLE分割槽表的設計
分割槽表的概念 分割槽致力於解決支援極大表和索引的關鍵問題。它採用他們分解成較小和易於管理的稱為分割槽的片 piece 的方法。一旦分割槽被定義,sql語句就可以訪問的操作某乙個分割槽而不是整個表,因而提高管理的效率。分割槽對於資料倉儲應用程式非常有效,因為他們常常儲存和分析巨量的歷史資料。分割槽表...