Sunteți pe pagina 1din 4

Anar Godjaev

http://anargodjaev.wordpress.com/

Table Partitions:
Range partition: The example below creates a table of four partitions, one for each quarter's sales. The columns sale_year, sale_month, and sale_day are the partitioning columns, while their values constitute a specific row's partitioning key. The VALUES LESS THAN clause determines the partition bound: rows with partitioning key values that compare less than the ordered list of values specified by the clause are stored in the partition. Each partition is given a name (sales_q1, sales_q2, ...), and each partition is contained in a separate tablespace (tsa, tsb, ...).
CREATE TABLE sales ( invoice_no NUMBER, sale_year INT NOT NULL, sale_month INT NOT NULL, sale_day INT NOT NULL ) PARTITION BY RANGE (sale_year, sale_month, sale_day) ( PARTITION sales_q1 VALUES LESS THAN (2012, 04, 01) TABLESPACE tsa, PARTITION sales_q2 VALUES LESS THAN (2012 07, 01) TABLESPACE tsb, PARTITION sales_q3 VALUES LESS THAN (2012, 10, 01) TABLESPACE tsc, PARTITION sales_q4 VALUES LESS THAN (2013, 01, 01) TABLESPACE tsd ); ALTER TABLE sales ADD PARTITION jan96 VALUES LESS THAN ( '26-FEB-2013' ) TABLESPACE tsx; ALTER TABLE sales DROP PARTITION dec98; ALTER INDEX sales_area_ix REBUILD; (if global index exists) DELETE FROM sales WHERE TRANSID < 10000; ALTER TABLE sales DROP PARTITION dec98 ALTER TABLE sales DROP PARTITION dec98 UPDATE GLOBAL INDEXES; ALTER TABLE four_seasons MERGE PARTITIONS quarter_one, quarter_two INTO PARTITION quarter_two; CREATE INDEX i_four_seasons_l ON four_seasons ( one,two ) LOCAL ( PARTITION i_quarter_one TABLESPACE i_quarter_one, PARTITION i_quarter_two TABLESPACE i_quarter_two, PARTITION i_quarter_three TABLESPACE i_quarter_three, PARTITION i_quarter_four TABLESPACE i_quarter_four ); ALTER TABLE four_seasons MODIFY PARTITION quarter_two REBUILD UNUSABLE LOCAL INDEXES; ALTER TABLE four_seasons TRUNCATE PARTITION quartes_one;

Anar Godjaev
Dropping index partitions:
ALTER INDEX npr DROP PARTITION P1; ALTER INDEX npr REBUILD PARTITION P2;

http://anargodjaev.wordpress.com/

Hash Partition: The following example creates a hashpartitioned table. The partitioning column is id, four partitions are created and assigned system generated names, and they are placed in four named tablespaces (gear1, gear2, ...).
CREATE TABLE scubagear (id NUMBER, name VARCHAR2 (60)) PARTITION BY HASH (id) PARTITIONS 4 STORE IN (gear1, gear2, gear3, gear4); ALTER TABLE scubagear ADD PARTITION p_named TABLESPACE gear5;

List Partition: The following example creates a listpartitioned table. It creates table q1_sales_by_region which is partitioned by regions consisting of groups of states.
CREATE TABLE q1_sales_by_region (deptno number, deptname varchar2(20), quarterly_sales number(10, 2), state varchar2(2)) PARTITION BY LIST (state) (PARTITION q1_northwest VALUES ('OR', 'WA'), PARTITION q1_southwest VALUES ('AZ', 'UT', 'NM'), PARTITION q1_northeast VALUES ('NY', 'VM', 'NJ'), PARTITION q1_southeast VALUES ('FL', 'GA'), PARTITION q1_northcentral VALUES ('SD', 'WI'), PARTITION q1_southcentral VALUES ('OK', 'TX')); ALTER TABLE q1_sales_by_region ADD PARTITION q1_nonmainland VALUES ('HI', 'PR') STORAGE (INITIAL 20K NEXT 20K) TABLESPACE tbs_3 NOLOGGING; ALTER TABLE q1_sales_by_region MERGE PARTITIONS q1_northcentral, q1_southcentral INTO PARTITION q1_central PCTFREE 50 STORAGE(MAXEXTENTS 20);

RangeHash Partition: The following statement creates a rangehash partitioned table. In this example, three range partitions are created, each containing eight subpartitions. Because the subpartitions are not named, system generated names are assigned, but the STORE IN clause distributes them

Anar Godjaev
across the 4 specified tablespaces (ts1, ...,ts4).

http://anargodjaev.wordpress.com/

CREATE TABLE scubagear (equipno NUMBER, equipname VARCHAR(32), price NUMBER) PARTITION BY RANGE (equipno) SUBPARTITION BY HASH(equipname) SUBPARTITIONS 8 STORE IN (ts1, ts2, ts3, ts4) (PARTITION p1 VALUES LESS THAN (1000), PARTITION p2 VALUES LESS THAN (2000), PARTITION p3 VALUES LESS THAN (MAXVALUE));

RangeList Partition: The following example illustrates how rangelist partitioning might be used. The example tracks sales data of products by quarters and within each quarter, groups it by specified states.
CREATE TABLE quarterly_regional_sales (deptno number, item_no varchar2(20), txn_date date, txn_amount number, state varchar2(2)) TABLESPACE ts4 PARTITION BY RANGE (txn_date) SUBPARTITION BY LIST (state) (PARTITION q1_2013 VALUES LESS THAN (TO_DATE('1-APR-2013','DD-MONYYYY')) (SUBPARTITION q1_2013_northwest VALUES ('OR', 'WA'), SUBPARTITION q1_2013_southwest VALUES ('AZ', 'UT', 'NM'), SUBPARTITION q1_2013_northeast VALUES ('NY', 'VM', 'NJ'), SUBPARTITION q1_2013_southeast VALUES ('FL', 'GA'), SUBPARTITION q1_2013_northcentral VALUES ('SD', 'WI'), SUBPARTITION q1_2013_southcentral VALUES ('OK', 'TX') ), PARTITION q2_2013 VALUES LESS THAN ( TO_DATE('1-JUL-2013','DD-MONYYYY')) (SUBPARTITION q2_2013_northwest VALUES ('OR', 'WA'), SUBPARTITION q2_2013_southwest VALUES ('AZ', 'UT', 'NM'), SUBPARTITION q2_2013_northeast VALUES ('NY', 'VM', 'NJ'), SUBPARTITION q2_2013_southeast VALUES ('FL', 'GA'), SUBPARTITION q2_2013_northcentral VALUES ('SD', 'WI'), SUBPARTITION q2_2013_southcentral VALUES ('OK', 'TX') ), PARTITION q3_2013 VALUES LESS THAN (TO_DATE('1-OCT-2013','DD-MONYYYY')) (SUBPARTITION q3_2013_northwest VALUES ('OR', 'WA'), SUBPARTITION q3_2013_southwest VALUES ('AZ', 'UT', 'NM'), SUBPARTITION q3_2013_northeast VALUES ('NY', 'VM', 'NJ'), SUBPARTITION q3_2013_southeast VALUES ('FL', 'GA'), SUBPARTITION q3_2013_northcentral VALUES ('SD', 'WI'), SUBPARTITION q3_2013_southcentral VALUES ('OK', 'TX') )); ALTER TABLE quarterly_regional_sales MODIFY SUBPARTITION q1_2013_southeast ADD VALUES ('KS');

Anar Godjaev
ALTER TABLE quarterly_regional_sales MODIFY SUBPARTITION q1_2013_southeast DROP VALUES ('KS');

http://anargodjaev.wordpress.com/

S-ar putea să vă placă și