(A) What is the interval partition
Interval partitioning is a new feature introduced in Oracle 11.1, this function can be automatically creates a corresponding input data partitions corresponding partition. In the absence of interval partitioning technology, DBA typically create a maxvalue partition to avoid ORA-14400: inserted partition key does not map to any partition ( "inserted partition key does not map to any partition") error.
A partition extended range (range partition), the spacer is inserted in the partition database command data table exceeds all existing range specified interval automatically create partitions partition. DBA partition must specify at least a higher value range, called the transition point, the database will automatically create a data partition of the interval beyond the transition point, the lower boundary of each interval is the upper boundary of the previous partition range or interval partitions.
(B) create interval partitions
(2.1) interval partitioning syntax for creating
CREATE TABLE table_name ( ... ) PARTITION BY RANGE(column1) INTERVAL expr [STORE IN (tablespace1,[tablespace2,...])] ( PARTITION partition_name1 VALUES LESS THAN(literal | MAXVALUE) [TABLESPACE tablespace1], PARTITION partition_name2 VALUES LESS THAN(literal | MAXVALUE) [TABLESPACE tablespace2] );
--PARTITION BY RANGE (column1): Specifies a partition column range
--INTERVAL: interval specified partition
--STORE IN: table memory space specified partition
(2.2) interval partitioning to create restrictions
Range interval partition is extended partition, which support a limited range, in Oracle 11g, spaced partitions can specify only one partition key column, and the data type or must NUMBER DATE type . Because the data type is DATE TIMESTAMP types of extensions can be used in the partition key. In conclusion, the interval partitions only supports NUMBER and TIME type.
(2.3) INTERVAL keyword interpretation
In the creation of an automatic interval partitions, the most central is the "INTERVAL" the keyword. For in time automatically partition, INTERVAL can be followed and NUMTOYMINTERVAL NUMTODSINTERVAL. Two keywords used as follows:
(2.3.1) Numto YM INTERVAL (x, c)
Usage: x is a data, c is a string, the function is the interval year to month x Switch type. Common units are: "year", "month" .
Example: the current time plus 3 years, 3 months plus the current time
SELECT SYSDATE, SYSDATE + NUMTOYMINTERVAL(3,'year') AS "3年后" , SYSDATE + NUMTOYMINTERVAL(3,'month') AS "3个月后" FROM dual;
(2.3.2)NUMTODSINTERVAL(x,c)
Usage: x is a data, c is a string, the function x is converted interval day to second type. Common units are: "day", "hour" , "minute", "second".
Examples: The current time plus 1 day, 1 hour, 1 minute, 1 second.
(C) the time (year, month, day, week) created interval partition
(3.1) Press "on" automatically create partitions (keyword: NUMTOYMINTERVAL)
Example: Creating an annual automatic partition table, according to staff birthday (birthday field), each year a partition.
--创建按年分区表 CREATE TABLE interval_year_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(birthday) INTERVAL (NUMTOYMINTERVAL(1,'year')) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition2014 VALUES LESS THAN(to_date('2015-01-01:00:00:00','yyyy-mm-dd hh24:mi:ss')), PARTITION partition2015 VALUES LESS THAN(to_date('2016-01-01:00:00:00','yyyy-mm-dd hh24:mi:ss')) );
(3.2) Press the "month" automatically create partitions (keyword: NUMTOYMINTERVAL)
Example: Create a monthly automatic partition table, according to staff birthday (birthday field), each month a partition.
-- 创建按月分区表 CREATE TABLE interval_month_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(birthday) INTERVAL (NUMTOYMINTERVAL(1,'month')) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition201401 VALUES LESS THAN(to_date('2014-02-01:00:00:00','yyyy-mm-dd hh24:mi:ss')) );
(3.3) press the "Day (Day)" automatically create partitions (keyword: NUMTODSINTERVAL)
Example: Creating a daily automatic partition table, according to staff birthday (birthday field), every day a partition.
-- 按天(日)创建分区 CREATE TABLE interval_day_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(birthday) INTERVAL (NUMTODSINTERVAL(1,'day')) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition20140101 VALUES LESS THAN(to_date('2014-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) );
(3.4) Press the "Week" automatically create partitions (keyword: NUMTODSINTERVAL)
Example: Create a weekly automatic partition table, according to staff birthday (birthday field), a weekly partition. Note that the key word here used the "day" partition, are "day", but was changed to seven days.
-- 按周创建分区 CREATE TABLE interval_week_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(birthday) INTERVAL (NUMTODSINTERVAL(7,'day')) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition201401w VALUES LESS THAN(to_date('2014-01-07 00:00:00','yyyy-mm-dd hh24:mi:ss')) );
(3.4) Press the "hour" is automatically created partitions (keyword: NUMTODSINTERVAL)
- Press the "h" partition
CREATE TABLE interval_hour_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(birthday) INTERVAL (NUMTODSINTERVAL(1,'hour')) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition20140100 VALUES LESS THAN(to_date('2014-01-01 01:00:00','yyyy-mm-dd hh24:mi:ss')) );
In addition, you can also press the "minutes", "seconds" automatically partition.
(D) Press the number (number) created interval partition
Examples: carried out in a relatively simple digital partition, where similar numbers 10 into the same partition
CREATE TABLE interval_number_table01 ( employee_id NUMBER, employee_name VARCHAR2(20), birthday DATE ) PARTITION BY RANGE(employee_id) INTERVAL (10) STORE IN (tbs01,tbs02,tbs03) ( PARTITION partition10 VALUES LESS THAN(10) );
(E) Frequently Asked Questions about interval partition
(5.1) How to convert the existing ordinary interval partition table
With the following command to an existing DPT conversion range interval partition table, note that only supports a range partitioned tables:
ALTER TABLE <table_name> SET INTERVAL <number or interval expression>;
(5.2) How to set a new interval for an existing table
Can use the following command to modify the interval, the operation does not cause the index is not available:
ALTER TABLE <table_name> SET INTERVAL(interval express);
See example MOS documents (1,479,115.1).
(5.3) to specify how to partition / table space to change the interval
INTERVAL STORE IN clause to specify the table space is created interval partition. If you specify a list of table space, will create a cyclic manner spaced partitions on the table space.
INTERVAL expr [STORE IN (tablespace1,[tablespace2,...])]
It should be noted that the use of "PARTITION" in INTERVAL clause to create a range of partition table space should be pointed out, otherwise will range partitioning to create the user's default table space, rather than the [STORE IN] table space.
For the partition has been created, you can use the following command to move it to a particular table space:
- moving the partition to a particular table space the ALTER TABLE < table_name > the MOVE the PARTITION < partition_name > TABLESPACE < tablespace_name > ; - Note: mobile partition causes the global index failure, need to be cautious
(5.4) What is the name of the partition interval is automatically created
Name interval partitioned database is created automatically generated, it can be viewed dba_tab_partition view. You can not assign a template to create a partition, but you can rename partitions.
The name of the automatically created Table space: Examples
insert into INTERVAL_NUMBER_TABLE01 values (201209, 'name09'); insert into INTERVAL_NUMBER_TABLE01 values (201210, 'name10'); insert into INTERVAL_NUMBER_TABLE01 values (201211, 'name11'); insert into INTERVAL_NUMBER_TABLE01 values (201212, 'name12'); insert into INTERVAL_NUMBER_TABLE01 values (201301, 'name01'); insert into INTERVAL_NUMBER_TABLE01 values (201402, 'name02'); insert into INTERVAL_NUMBER_TABLE01 values (201503, 'name03'); SQL> select table_owner,table_name,partition_name,high_value,tablespace_name,interval 2 from dba_tab_partitions 3 where table_name = 'INTERVAL_NUMBER_TABLE01'; TABLE_OWNER TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME INTERVAL -------------- ------------------------------ ----------------- ------------ ----------------- -------- LIJIAMAN INTERVAL_NUMBER_TABLE01 PARTITION10 10 USERS NO LIJIAMAN INTERVAL_NUMBER_TABLE01 SYS_P54 20 TBS02 YES LIJIAMAN INTERVAL_NUMBER_TABLE01 SYS_P55 110 TBS02 YES LIJIAMAN INTERVAL_NUMBER_TABLE01 SYS_P56 120 YES TBS03 LIJIAMAN INTERVAL_NUMBER_TABLE01 SYS_P57 130 TBS01 YES - Note: partition INTERVAL = 'YES' representatives created automatically
(5.5) when using DBMS_METADATA.GET_DDL retrieval table, why the lack of space partition system-generated?
"DBMS_METADATA.GET_DDL" only provides users the means to create a partition without providing the system automatically generates a partition. The following test examples:
SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','INTERVAL_NUMBER_TABLE01','LIJIAMAN') FROM DUAL;
DBMS_METADATA.GET_DDL('TABLE', -------------------------------------------------------------------------------- CREATE TABLE "LIJIAMAN"."INTERVAL_NUMBER_TABLE01" ( "EMPLOYEE_ID" NUMBER, "EMPLOYEE_NAME" VARCHAR2(20), "BIRTHDAY" DATE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE( BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" PARTITION BY RANGE ("EMPLOYEE_ID") INTERVAL (10) STORE IN ("TBS01", "TBS02", "TBS03") (PARTITION "PARTITION10" VALUES LESS THAN (10) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 8388608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" )
If you want to output the script partitions automatically created, EXPORT parameters DBMS_METDATA needs to be set to true
exec dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,'EXPORT',true);
(Vi) bug on interval partitions
Previously, when using the partition table, created by the delay encountered paragraph (deferred_segment_creation) segment due to abnormal distribution problem. Interval partition has a similar bug, use caution.
Bug 16042673 - Database hang when system trying to add interval partition to the table (Doc ID 16042673.8)
Symptoms:
Related To:
- Hang (Process Hang)
- Waits for "library cache lock"
- Waits for "library cache load lock"
Description
This bug is only relevant when using Partitioned TablesConcurrent insert statements issued against an interval partitioned table resulting in the creation of a new partition blocks remaining inserts into the same table. Rediscovery Notes If concurrent insert statements are issued against an interval partitioned table and the insert statement which results in the creation of a new partition blocks all the other inserts into the table, then we might be encountering this bug.
Pros and cons of thinking (seven) interval partition
Benefits: Interval partition is created automatically by the system partition, reducing the daily operation and maintenance work DBA, to avoid this type of error ORA-14400, end of year do not need to create partitions manually each year for the next year, think about was quite happy;
Disadvantages: Because the system automatically creates a partition name, we are unable to determine where the data partition by name, increasing the difficulty of maintenance later. For example, if a DBA manual maintenance is January 2019 assuming that the data partition table "part_201901" stored, if we want to delete the data in January, the partition can be deleted directly, if the database there are 500 similar table, direct write batch script "ALTER tABLE <table_name> DROP pARTITION part_201901" January will be all deleted data table, but for the partition automatically created at different tables inside, the data in January 2019 different corresponding partition name, they can not use a script to batch delete, even if the script is also very troublesome.
-------------------------------------------------------------------------------------------------------
Personal partition (partition) technology-related documents:
1. [Oracle] Learning partition table
2. [the Oracle] partition index
3. the Oracle table partition delete partition initiator error ORA-01502: index or index of such a partition in an unusable state
4. the Oracle Split Partition Table error caused ORA-01502
5. the the Oracle online redefinition (online redefinition) - ordinary partition table to table
Reference documents:
1. Interval Partitioning Essentials - Common Questions - Top Issues (Doc ID 1479115.1)
2. How to Build an INTERVAL PARTIONED Table using a NUMBER datatype for the INTERVAL Partition. (Doc ID 1514047.1)
3. Bug 16042673 - Database hang when system trying to add interval partition to the table (Doc ID 16042673.8)
-------------------------------------------------------------------------------------------------------