Oracle 10g使用比較多的兩種分區(qū)類(lèi)型:
(1)范圍分區(qū)(range);
(2)哈希分區(qū)(hash)。
(1)Range分區(qū):是應(yīng)用范圍比較廣的表分區(qū)方式,它是以列的值的范圍來(lái)做為分區(qū)的劃分條件,將記錄存放到列值所在的range分區(qū)中。
例:按照時(shí)間劃分,2010年1月的數(shù)據(jù)放到a分區(qū),2月的數(shù)據(jù)放到b分區(qū),在創(chuàng)建的時(shí)候,需要指定基于的列,以及分區(qū)的范圍值。在按時(shí)間分區(qū)時(shí),如果某些記錄暫無(wú)法預(yù)測(cè)范圍,可以創(chuàng)建maxvalue分區(qū),所有不在指定范圍內(nèi)的記錄都會(huì)被存儲(chǔ)到maxvalue所在分區(qū)中。
ddl:create table pdba (id number, time date) partition by range (time)(
partition p1 values less than (to_date('2010-10-1', 'yyyy-mm-dd')),
partition p2 values less than (to_date('2010-11-1', 'yyyy-mm-dd')),
partition p3 values less than (to_date('2010-12-1', 'yyyy-mm-dd')),
partition p4 values less than (maxvalue))
(2)Hash分區(qū):對(duì)于那些無(wú)法有效劃分范圍的表,可以使用hash分區(qū),這樣對(duì)于提高性能還是會(huì)有一定的幫助。hash分區(qū)會(huì)將表中的數(shù)據(jù)平均分配到你指定的幾個(gè)分區(qū)中,列所在分區(qū)是依據(jù)分區(qū)列的hash值自動(dòng)分配,因此你并不能控制也不知道哪條記錄會(huì)被放到哪個(gè)分區(qū)中,hash分區(qū)也可以支持多個(gè)依賴(lài)列。
ddl:create table test(
transaction_id number primary key,
item_id number(8) not null)
partition by hash(transaction_id)(
partition part_01 tablespace tablespace01,
partition part_02 tablespace tablespace02,
partition part_03 tablespace tablespace03);