-
Tables greater than 2 GB should always be considered as candidates for partitioning.
表的數據超過2GB的時候應該考慮使用分區表
-
Tables containing historical data, in which new data is added into the newest partition. A typical example is a historical table where only the current month's data is updatable and the other 11 months are read only.
表中有歷史數據,但是新的數據只進入新的分區
-
When the contents of a table must be distributed across different types of storage devices.
PARTITION BY RANGE (column[, column ]...)
[ INTERVAL ( expr ) [ STORE IN ( tablespace [, tablespace]...) ]]
( PARTITION [ partition ]
range_values_clause table_partition_description
[, PARTITION [ partition ]
range_values_clause table_partition_description
]...
)
需要我們指定的有:
l column:分區依賴列(如果是多個,以逗號分隔);
l partition:分區名稱;
l values less than:後跟分區範圍值(如果依賴列有多個,範圍對應值也應是多個,中間以逗號分隔);
l tablespace_clause:分區的存儲屬性,例如所在表空間等屬性(可爲空),默認繼承基表所在表空間的屬性。
2 partition by range(id)(3 partition t_range_p1 values less than (100) tablespace founder,4 partition t_range_p2 values less than (200) tablespace founder01,5 partition t_range_p3 values less than (maxvalue) tablespace founder026 );
OWNER TABLE_NAME TABLESPACE_NAME PAR------------------------------- ----------------------------- ------------------------- -------FOUNDER TEST_PARTITION_RANGE YES
SQL> select partition_name,high_value,tablespace_name,table_name from dba_tab_partitions where table_name='TEST_PARTITION_RANGE' order by partition_position;TABLE_NAME PARTITI PARTITION_COUNT------------------------------ ------- ---------------TEST_PARTITION_RANGE RANGE 3
我們來看看oracle是如何給分區表分配空間的PARTITION_NAME HIGH_VALUE TABLESPACE_NAME TABLE_NAME--------------- ---------------- ---------------- ------------------------- -----------------------------------T_RANGE_P1 100 FOUNDER TEST_PARTITION_RANGET_RANGE_P2 200 FOUNDER01 TEST_PARTITION_RANGET_RANGE_P3 MAXVALUE FOUNDER02 TEST_PARTITION_RANGE
SQL> select segment_name,partition_name,segment_type,tablespace_name,header_file,header_block from dba_segments t where t.segment_name='TEST_PARTITION_RANGE';
PARTITION BY HASH (column [, column ] ...)
{ individual_hash_partitions
|hash_partitions_by_quantity
}
所以創建分區有兩種方法:
SQL> create table dept2 (deptno number,deptname varchar2(32))
2 partition by hash(deptno) partitions 4;
方法二:指定分區的名字
SQL> create table dept3 (deptno number,deptname varchar2(32))
2 partition by hash(deptno)
3 (partition p1 tablespace founder
4 partition p2 tablespace founder02);
(PARTITION [ partition ]
list_values_clause table_partition_description
[, PARTITION [ partition ]
list_values_clause table_partition_description
]...
)
例子如下:
create table sales_list (salesman_id number(5), salesman_name varchar2(30), sales_state varchar2(20), sales_amount number(10), sales_date date) partition by list (sales_state) ( partition sales_west values ('California','Hawaii') tablespace x, partition sales_east values ('New York','Virginia') tablespace y, partition sales_central values ('Texas','Illinois') tablespace z, partition sales_other values(DEFAULT) tablespace o );