Example: Splitting a RANGE subpartition v17
This example splits a range subpartition, redistributing the subpartition's contents between two new subpartitions.
The sample table sales
was created with the command:
CREATE TABLE sales ( dept_no number, part_no varchar2, country varchar2(20), date date, amount number ) PARTITION BY LIST(country) SUBPARTITION BY RANGE(date) ( PARTITION europe VALUES('FRANCE', 'ITALY') ( SUBPARTITION europe_2011 VALUES LESS THAN('2012-Jan-01'), SUBPARTITION europe_2012 VALUES LESS THAN('2013-Jan-01') ), PARTITION asia VALUES('INDIA', 'PAKISTAN') ( SUBPARTITION asia_2011 VALUES LESS THAN('2012-Jan-01'), SUBPARTITION asia_2012 VALUES LESS THAN('2013-Jan-01') ), PARTITION americas VALUES('US', 'CANADA') ( SUBPARTITION americas_2011 VALUES LESS THAN('2012-Jan-01'), SUBPARTITION americas_2012 VALUES LESS THAN('2013-Jan-01') ) );
The sales
table has the partitions europe
, asia
, and americas
. Each partition has two range-defined subpartitions that sort the partitions contents into subpartitions by the value of the date
column:
edb=# SELECT partition_name, subpartition_name, high_value FROM ALL_TAB_SUBPARTITIONS;
partition_name | subpartition_name | high_value ----------------+-------------------+---------------------- EUROPE | EUROPE_2011 | '01-JAN-12 00:00:00' EUROPE | EUROPE_2012 | '01-JAN-13 00:00:00' ASIA | ASIA_2011 | '01-JAN-12 00:00:00' ASIA | ASIA_2012 | '01-JAN-13 00:00:00' AMERICAS | AMERICAS_2011 | '01-JAN-12 00:00:00' AMERICAS | AMERICAS_2012 | '01-JAN-13 00:00:00' (6 rows)
This command adds rows to each subpartition:
INSERT INTO sales VALUES (10, '4519b', 'FRANCE', '17-Jan-2012', '45000'), (20, '3788a', 'INDIA', '01-Mar-2012', '75000'), (40, '9519b', 'US', '12-Apr-2012', '145000'), (20, '3788a', 'PAKISTAN', '04-Jun-2012', '37500'), (40, '4577b', 'US', '11-Nov-2012', '25000'), (30, '7588b', 'CANADA', '14-Dec-2012', '50000'), (30, '9519b', 'CANADA', '01-Feb-2012', '75000'), (30, '4519b', 'CANADA', '08-Apr-2012', '120000'), (40, '3788a', 'US', '12-May-2012', '4950'), (10, '9519b', 'ITALY', '07-Jul-2012', '15000'), (10, '9519a', 'FRANCE', '18-Aug-2012', '650000'), (10, '9519b', 'FRANCE', '18-Aug-2012', '650000'), (20, '3788b', 'INDIA', '21-Sept-2012', '5090'), (40, '4788a', 'US', '23-Sept-2012', '4950'), (40, '4788b', 'US', '09-Oct-2012', '15000'), (20, '4519a', 'INDIA', '18-Oct-2012', '650000'), (20, '4519b', 'INDIA', '2-Dec-2012', '5090');
A SELECT
statement confirms that the rows are distributed among the subpartitions:
edb=# SELECT tableoid::regclass, * FROM sales;
tableoid |dept_no|part_no| country | date | amount --------------------+-------+-------+---------+--------------------+--------- sales_americas_2012| 40 | 9519b | US | 12-APR-12 00:00:00 | 145000 sales_americas_2012| 40 | 4577b | US | 11-NOV-12 00:00:00 | 25000 sales_americas_2012| 30 | 7588b | CANADA | 14-DEC-12 00:00:00 | 50000 sales_americas_2012| 30 | 9519b | CANADA | 01-FEB-12 00:00:00 | 75000 sales_americas_2012| 30 | 4519b | CANADA | 08-APR-12 00:00:00 | 120000 sales_americas_2012| 40 | 3788a | US | 12-MAY-12 00:00:00 | 4950 sales_americas_2012| 40 | 4788a | US | 23-SEP-12 00:00:00 | 4950 sales_americas_2012| 40 | 4788b | US | 09-OCT-12 00:00:00 | 15000 sales_europe_2012 | 10 | 4519b | FRANCE | 17-JAN-12 00:00:00 | 45000 sales_europe_2012 | 10 | 9519b | ITALY | 07-JUL-12 00:00:00 | 15000 sales_europe_2012 | 10 | 9519a | FRANCE | 18-AUG-12 00:00:00 | 650000 sales_europe_2012 | 10 | 9519b | FRANCE | 18-AUG-12 00:00:00 | 650000 sales_asia_2012 | 20 | 3788a | INDIA | 01-MAR-12 00:00:00 | 75000 sales_asia_2012 | 20 | 3788a | PAKISTAN| 04-JUN-12 00:00:00 | 37500 sales_asia_2012 | 20 | 3788b | INDIA | 21-SEP-12 00:00:00 | 5090 sales_asia_2012 | 20 | 4519a | INDIA | 18-OCT-12 00:00:00 | 650000 sales_asia_2012 | 20 | 4519b | INDIA | 02-DEC-12 00:00:00 | 5090 (17 rows)
This command splits the americas_2012
subpartition into two new subpartitions and redistributes the contents:
ALTER TABLE sales SPLIT SUBPARTITION americas_2012 AT('2012-Jun-01') INTO ( SUBPARTITION americas_p1_2012, SUBPARTITION americas_p2_2012 );
After the command is invoked, the americas_2012
subpartition is deleted. In its place, the server creates the subpartitions americas_p1_2012
and americas_p2_2012
:
edb=# SELECT partition_name, subpartition_name, high_value FROM ALL_TAB_SUBPARTITIONS;
partition_name | subpartition_name | high_value ----------------+-------------------+---------------------- EUROPE | EUROPE_2011 | '01-JAN-12 00:00:00' EUROPE | EUROPE_2012 | '01-JAN-13 00:00:00' ASIA | ASIA_2011 | '01-JAN-12 00:00:00' ASIA | ASIA_2012 | '01-JAN-13 00:00:00' AMERICAS | AMERICAS_2011 | '01-JAN-12 00:00:00' AMERICAS | AMERICAS_P1_2012 | '01-JUN-12 00:00:00' AMERICAS | AMERICAS_P2_2012 | '01-JAN-13 00:00:00' (7 rows)
Querying the sales
table shows that the subpartition's contents are redistributed:
edb=# SELECT tableoid::regclass, * FROM sales;
tableoid |dept_no|part_no|country | date | amount -----------------------+-------+-------+---------+-------------------+------- sales_americas_p1_2012| 40 | 9519b | US | 12-APR-12 00:00:00|145000 sales_americas_p1_2012| 30 | 9519b | CANADA | 01-FEB-12 00:00:00|75000 sales_americas_p1_2012| 30 | 4519b | CANADA | 08-APR-12 00:00:00|120000 sales_americas_p1_2012| 40 | 3788a | US | 12-MAY-12 00:00:00| 4950 sales_americas_p2_2012| 40 | 4577b | US | 11-NOV-12 00:00:00|25000 sales_americas_p2_2012| 30 | 7588b | CANADA | 14-DEC-12 00:00:00|50000 sales_americas_p2_2012| 40 | 4788a | US | 23-SEP-12 00:00:00| 4950 sales_americas_p2_2012| 40 | 4788b | US | 09-OCT-12 00:00:00|15000 sales_europe_2012 | 10 | 4519b | FRANCE | 17-JAN-12 00:00:00|45000 sales_europe_2012 | 10 | 9519b | ITALY | 07-JUL-12 00:00:00|15000 sales_europe_2012 | 10 | 9519a | FRANCE | 18-AUG-12 00:00:00|650000 sales_europe_2012 | 10 | 9519b | FRANCE | 18-AUG-12 00:00:00|650000 sales_asia_2012 | 20 | 3788a | INDIA | 01-MAR-12 00:00:00|75000 sales_asia_2012 | 20 | 3788a | PAKISTAN| 04-JUN-12 00:00:00|37500 sales_asia_2012 | 20 | 3788b | INDIA | 21-SEP-12 00:00:00|5090 sales_asia_2012 | 20 | 4519a | INDIA | 18-OCT-12 00:00:00|650000 sales_asia_2012 | 20 | 4519b | INDIA | 02-DEC-12 00:00:00| 5090 (17 rows)