All About Table & Index Local and Global Partitioning

CREATE TABLE TBL_TXN
(
USER_ID VARCHAR2(15 BYTE) NOT NULL,
TRANS_DATE DATE NOT NULL,
SERVICE_TYPE NUMBER NOT NULL
)
PARTITION BY RANGE (TRANS_DATE)
SUBPARTITION BY LIST(SERVICE_TYPE)
SUBPARTITION TEMPLATE(
SUBPARTITION type1 VALUES (1) TABLESPACE USERS,
SUBPARTITION type2 VALUES (2) TABLESPACE USERS,
SUBPARTITION type3 VALUES (3) TABLESPACE USERS)
(PARTITION TXN_010311 VALUES LESS THAN (TO_DATE(' 2011-03-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS,
PARTITION TXN_020311 VALUES LESS THAN (TO_DATE(' 2011-03-03 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS,
PARTITION TXN_030311 VALUES LESS THAN (TO_DATE(' 2011-03-04 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS
)

alter table TBL_TXN add partition TXN_040311 VALUES LESS THAN (TO_DATE(' 2011-03-05 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS;

CREATE INDEX TXN_IDX_DATE on TBL_TXN (TRANS_DATE) LOCAL tablespace USERS;
CREATE INDEX TXN_IDX_TYPE on TBL_TXN (SERVICE_TYPE) tablespace USERS;


insert into tbl_txn values (100,'01-MAR-2011',1);
insert into tbl_txn values (100,'01-MAR-2011',2);
insert into tbl_txn values (100,'01-MAR-2011',3);
insert into tbl_txn values (101,'04-MAR-2011',1);
insert into tbl_txn values (101,'04-MAR-2011',2);
insert into tbl_txn values (101,'04-MAR-2011',3);
insert into tbl_txn values (100,'02-MAR-2011',1);
insert into tbl_txn values (100,'02-MAR-2011',2);
insert into tbl_txn values (100,'02-MAR-2011',3);
insert into tbl_txn values (101,'03-MAR-2011',1);
insert into tbl_txn values (101,'03-MAR-2011',2);
insert into tbl_txn values (101,'03-MAR-2011',3);
insert into tbl_txn values (102,'03-MAR-2011',1);
insert into tbl_txn values (102,'03-MAR-2011',2);
insert into tbl_txn values (102,'03-MAR-2011',3);

commit;

exec dbms_stats.gather_table_stats('PARTTEST','TBL_TXN', estimate_percent => 10,cascade=>true);

select * from tbl_txn partition (trans_max);
select * from tbl_txn subpartition (trans_max_type2);

#########

--maxvalue

CREATE TABLE TBL_TRANS
(
USER_ID VARCHAR2(15 BYTE) NOT NULL,
TRANS_DATE DATE NOT NULL,
SERVICE_TYPE NUMBER NOT NULL
)
PARTITION BY RANGE (TRANS_DATE)
SUBPARTITION BY LIST(SERVICE_TYPE)
SUBPARTITION TEMPLATE(
SUBPARTITION type1 VALUES (1) TABLESPACE USERS,
SUBPARTITION type2 VALUES (2) TABLESPACE USERS,
SUBPARTITION type3 VALUES (3) TABLESPACE USERS)
(PARTITION TRANS_010311 VALUES LESS THAN (TO_DATE(' 2011-03-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS,
PARTITION TRANS_020311 VALUES LESS THAN (TO_DATE(' 2011-03-03 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS,
PARTITION TRANS_030311 VALUES LESS THAN (TO_DATE(' 2011-03-04 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) TABLESPACE USERS,
PARTITION TRANS_MAX VALUES LESS THAN (MAXVALUE) TABLESPACE USERS
)


insert into TBL_TRANS values (100,'01-MAR-2011',1);
insert into TBL_TRANS values (100,'01-MAR-2011',2);
insert into TBL_TRANS values (100,'01-MAR-2011',3);
insert into TBL_TRANS values (101,'01-MAR-2011',1);
insert into TBL_TRANS values (101,'01-MAR-2011',2);
insert into TBL_TRANS values (101,'01-MAR-2011',3);
insert into TBL_TRANS values (102,'01-MAR-2011',1);
insert into TBL_TRANS values (102,'01-MAR-2011',2);
insert into TBL_TRANS values (102,'01-MAR-2011',3);
insert into TBL_TRANS values (100,'02-MAR-2011',1);
insert into TBL_TRANS values (100,'02-MAR-2011',2);
insert into TBL_TRANS values (100,'02-MAR-2011',3);
insert into TBL_TRANS values (101,'03-MAR-2011',1);
insert into TBL_TRANS values (101,'03-MAR-2011',2);
insert into TBL_TRANS values (101,'03-MAR-2011',3);
insert into TBL_TRANS values (102,'03-MAR-2011',1);
insert into TBL_TRANS values (102,'03-MAR-2011',2);
insert into TBL_TRANS values (102,'03-MAR-2011',3);

insert into TBL_TRANS values (102,'04-MAR-2011',1);
insert into TBL_TRANS values (102,'04-MAR-2011',2);
insert into TBL_TRANS values (102,'04-MAR-2011',3);

commit;

CREATE INDEX TRANS_IDX_DATE on TBL_TRANS (TRANS_DATE) LOCAL tablespace USERS;
CREATE INDEX TRANS_IDX_TYPE on TBL_TRANS (SERVICE_TYPE) tablespace USERS;

exec dbms_stats.gather_table_stats('PARTTEST','TBL_TXN', estimate_percent => 10,cascade=>true);

select * from tbl_trans partition (trans_max);
select * from tbl_trans subpartition (trans_max_type1);

##########################

select index_name, index_type, table_name, status from dba_indexes where table_name='TXN';
select index_name, partition_name, status from dba_ind_partitions where index_name='TXN_IDX_DATE';
select index_name, index_type, table_name, status from dba_indexes where table_name='TBL_TRANS';

##########################

alter table parttest.TBL_TRANS SPLIT PARTITION TRANS_MAX AT (TO_DATE('06-MAR-2011 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
INTO (PARTITION TRANS_050311, PARTITION TRANS_MAX);

Comments

Popular posts from this blog

Restoring Master, Model and MSDB from Netbackup

Oracle Job Operations