SlideShare a Scribd company logo
Data warehouse Design Using Oracle
https://www.oercommons.org/authorin
g/edit/21861
Dr. Girija Narasimhan 1
OER- UNIT 4 PARTITION
PARTITION
TABLESPACE
2Dr.Girija Narasimhan
Oracle Database allocates logical
space for all data in the
database.
The logical units of database
space allocation are data blocks,
extents, segments, and
tablespaces.
At a physical level, the data is
stored in data files on disk
The data in the data files is
stored in operating system
blocks.
3Dr.Girija Narasimhan
Data blocks are the smallest
units storing data in the
oracle database
An extent is a set of logically
contiguous data blocks
allocated for storing a specific
type of information
A segment is a set of extents
allocated for a specific
database object, such as a
table.
Each segment belongs to one
and only one tablespace
4Dr.Girija Narasimhan
The database has one or more table space.
Table space is called as logical storage unit within an oracle
database.
The meaning of logical is table space is not visible in the file
system.
Table space has at least had one data file. Each table space has
unique data file.
Each table space is divided into based on the size mentioned in
the “Create tablespace” statement.
The table space builds the bridge between the oracle database
and the file system in which the table’s or index data is stored
5Dr.Girija Narasimhan
CREATE TABLESPACE dwuser01a
DATAFILE 'c:tempdwuser1a.dbf' SIZE 40M
BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K
SEGMENT SPACE MANAGEMENT AUTO ONLINE;
In the Lab session students are sharing single server, then each
user created different dbf file in the c:temp- otherwise “already
.dbf” file exist error will occur.
For example: ‘c:tempuser1.dbf’. .c:tempuser2.dbf’
6Dr.Girija Narasimhan
DROP TABLE SPACE
7Dr.Girija Narasimhan
Dr.Girija Narasimhan 8
You can drop a tablespace and its contents (the segments contained
in the tablespace) from the database if the tablespace and its
contents are no longer required
Once a tablespace has been dropped, the data in the tablespace is
not recoverable.
Therefore, make sure that all data contained in a tablespace to be
dropped will not be required in the future
SQL> drop tablespace ica;
This will drop the tablespace only if it is empty
Dr.Girija Narasimhan 9
Tablespace is not empty and if you want to drop it anyhow then add
the following keyword
SQL>drop tablespace ica including contents;
This will drop the tablespace even if it is not empty.
But the data files will not be deleted you have to use operating
system command to delete the files.
But If you include data files keyword then, the associated data files
will also be deleted from the disk.
SQL>drop tablespace ica including contents and
datafiles;
various types of partition
10Dr.Girija Narasimhan
Dr.Girija Narasimhan 11
CREATE TABLE <Table name>
RANGE PARTITION LIST
PARTITION
HASH
PARTITION
RANGE PARTITION
Using Number Values
RANGE PARTITION
Using Alphabet Values
RANGE PARTITION
Using DATE Values
Partition Type Partition
Type
Partition Type
COMPOSITE
PARTITION
12Dr.Girija Narasimhan
RANGE PARTITION
Using Number Values
13Dr.Girija Narasimhan
Dr.Girija Narasimhan 14
create table interval_part(pid number(5) not null,
fname varchar2(30),
lname varchar2(30) )
partition by range(pid)
(
partition p1 values less than(101)
)
tablespace dwuser01a;
Insert into INTERVAL_PART values(100,’Ali’,’Ahmed’);
Insert into INTERVAL_PART values(101,’Zahra’,’Khamis’);
PARTITION TYPE
PARTITION NAME
COLUMN NAME
Insert values into the interval_part and check whether the records are storing in the assign
partition
As per given condition, the maximum value is 100, it will store only the first record only. It
will give error message, for the value of product id 101 no partition was assigned
Dr.Girija Narasimhan 15
SELECT PARTITION_NAME, TABLESPACE_NAME, HIGH_VALUE FROM USER_TAB_PARTITIONS;
PARTITION_NAME TABLESPACE_NAME HIGH_VALUE
-----------------------------------------------------------------------------
P1 dwuser01a 101
SELECT * FROM INTERVAL_PART PARTITION(P1);
PID FNAME LNAME
---------- --------------- -----------------
100 Ali Ahmed
Insert into interval_part values(101,'zahra','khamis')
*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any
partition
The USER_TAB_PARTITIONS describes the partition information as name of the
partition, tablespace name, storage parameter or value range of the partition .
Display the values stored in the partition.
RANGE PARTITION
Using Alphabet Values
16Dr.Girija Narasimhan
Dr.Girija Narasimhan 17
Create table product_alpha(Pid number(4) primary key , pname
varchar2(25),pcategory varchar2(20))
PARTITION BY RANGE(pcategory)(
Partition pcategoy_ae VALUES LESS THAN(‘F%’) TABLESPACE part1,
Partition pcategoy_fl VALUES LESS THAN(‘M%’) TABLESPACE part2,
Partition pcategoy_mr VALUES LESS THAN(‘S%’) TABLESPACE part3,
Partition pcategoy_sz VALUES LESS THAN(MAXVALUE) TABLESPACE part4);
Range partition using partition key based on character based values.
This type of partition is useful for based on location name, country
and supplier based analysis in the data warehousing.
This is the alternative to numeric based values.
It will store the values “a,b,c,d,e”
It will store the exceed
values of all the partition
Store each partition in
different tablespace
Dr.Girija Narasimhan 18
SELECT PARTITION_NAME,TABLESPACE_NAME,HIGH_VALUE FROM
USER_TAB_PARTITIONS;
PARTITION_NAME TABLESPACE_NAME HIGH_VALUE
----------------------------- -------------------------------- -------------------
PCATEGOY_SZ PART4 MAXVALUE
PCATEGOY_AE PART1 'F%'
PCATEGOY_FL PART2 'M%'
PCATEGOY_MR PART3 'S%‘
Insert into Product_alpha values(100,’Sony LCD 32”’,’TV’);
Insert into Product_alpha values(200,’Sony POWER SHOT’,’CAMERA’);
Insert into Product_alpha values(300,’Sony 3G Dual SIM’,’MOBILE’);
Insert into product_alpha values(400,’Cannon Digit power’,’DIGITAL CAMERA’);
Dr.Girija Narasimhan 19
SELECT * FROM Product_alpha PARTITION(PCATEGOY_AE);
PID PNAME PCATEGORY
---------- --------------------------- --------------------
200 Sony POWER SHOT CAMERA
400 Cannon Digit power DIGITAL CAMERA
SELECT * FROM Product_alpha PARTITION(PCATEGOY_FL);
no rows selected
SELECT * FROM Product_alpha PARTITION(PCATEGOY_MR);
PID PNAME PCATEGORY
---------- ------------------------- --------------------
300 Sony 3G Dual SIM MOBILE
SELECT * FROM Product_alpha PARTITION(PCATEGOY_SZ);
PID PNAME PCATEGORY
--------- ------------------------- --------------------
100 Sony LCD 32” TV
RANGE PARTITION
Using DATE Values
20Dr.Girija Narasimhan
Dr.Girija Narasimhan 21
CREATE TABLE Productrange_date (
Pid number(4) Primary key,pname varchar2(25),expdate date NOT Null)
PARTITION BY RANGE(expdate)(
PARTITION yr0 VALUES LESS THAN (TO_DATE('01-JAN-2007','DD-MON-YYYY')) TABLESPACE part1,
PARTITION yr1 VALUES LESS THAN (TO_DATE('01-JAN-2008','DD-MON-YYYY')) TABLESPACE part2,
PARTITION yr2 VALUES LESS THAN (TO_DATE('01-JAN-2009','DD-MON-YYYY')) TABLESPACE part3,
PARTITION yr3 VALUES LESS THAN (MAXVALUE) TABLESPACE part4);
INSERT INTO Productrange_date VALUES (1001, ‘Orange’, ’21-MAY-08’);
INSERT INTO Productrange_date VALUES (1002, ‘Sugar’, ’16-MAY-09’);
INSERT INTO Productrange_date VALUES (1003, ‘Biscutt’, ’12-NOV-09’);
SQL> select * from productrange_date;
PID PNAME EXPDATE
---------- ------------------------- -------------
1001 Orange 21-MAY-08
1002 Sugar 16-MAY-09
1003 Biscutt 12-NOV-09
The partition key in the range partition to be Date based.
It is useful for analyzing table data week wise or day wise.
Store values upto 31-dec-2006
Dr.Girija Narasimhan 22
SELECT * FROM productrange_date PARTITION(yr1);
no rows selected
SELECT * FROM productrange_date PARTITION(yr2);
PID PNAME EXPDATE
---------- -- ------------- -------------
1001 Orange 21-MAY-08
SELECT * FROM productrange_date PARTITION(yr3);
PID PNAME EXPDATE
--------- --------------- -------------
1002 Sugar 16-MAY-09
1003 Biscutt 12-NOV-09
ALTER TABLE
ADD PARTITION
23Dr.Girija Narasimhan
Dr.Girija Narasimhan 24
ALTER TABLE <Table name>
ADD PARTITION
RANAME PARTITION
DROP PARTITION
MERGE PARTITION
ADD PARTITION
Using Alter table – ADD Partition statement, it is possible to
insert new partition details of already existed partition
Alter table INTERVAL_PART
ADD partition p2 values less than(201);
SELECT PARTITION_NAME,TABLESPACE_NAME,HIGH_VALUE FROM
USER_TAB_PARTITIONS;
PARTITION_NAME TABLESPACE_NAME HIGH_VALUE
-------------------------- ---------------- -----------------
P1 UWDATA 101
P2 UWDATA 201
SELECT * FROM INTERVAL_PART partition(P1);
PID FNAME LNAME
---------- ------------------------- --------------
100 Ali Ahmed
SELECT * FROM INTERVAL_PART partition(P2);
PID FNAME LNAME
---------- ------------------------- --------------
101 Zahra Khamis
200 Mohammed Omar
Insert into INTERVAL_PART values(101,'zahra','khamis');
Insert into INTERVAL_PART values(200,'Mohammed','omar');
SELECT * FROM INTERVAL_PART;
PID FNAME LNAME
---------- ------------------------- --------------
100 Ali Ahmed
101 Zahra Khamis
200 Mohammed Omar
ALTER TABLE
RENAME PARTITION
27Dr.Girija Narasimhan
ALTER TABLE INTERVAL_PART
RENAME PARTITION P1 TO P9;
SQL> SELECT partition_name FROM user_tab_partitions WHERE
PARTITION_NAME='P9';
PARTITION_NAME
--------------------------
P9
SQL> SELECT * FROM INTERVAL_PART partition(P9);
PID FNAME LNAME
---------- -------------- ---------------
100 Ali Ahmed
ALTER TABLE
MERGE PARTITION
29Dr.Girija Narasimhan
Dr.Girija Narasimhan 30
SELECT * FROM productrange_date PARTITION(yr2);
PID PNAME EXPDATE
---------- -- ------------- -------------
1001 Orange 21-MAY-08
SELECT * FROM productrange_date PARTITION(yr3);
PID PNAME EXPDATE
--------- --------------- -------------
1002 Sugar 16-MAY-09
1003 Biscutt 12-NOV-09
Alter table productrange_date merge partitions yr2,yr3
into partition yr6;
SELECT * FROM productrange_date PARTITION(yr6)
PID PNAME EXPDATE
--------- ------------------ ---------
1001 Orange 22-MAY-08
1002 Sugar 16-MAY-09
1003 Biscutt 12-NOV-09
Merge partition
creates a new
partition called yr6
It copies the values
from yr2 and yr3
ALTER TABLE
DROP PARTITION
31Dr.Girija Narasimhan
Dr.Girija Narasimhan 32
Alter table Product_alpha drop partition pcategoy_ae;
SELECT * FROM Product_alpha PARTITION(PCATEGOY_AE);
PID PNAME PCATEGORY
---------- --------------------------- --------------------
200 Sony POWER SHOT CAMERA
400 Cannon Digit power DIGITAL CAMERA
SELECT * FROM Product_alpha;
PID PNAME PCATEGORY
---------- ----------------------------- --------------------
200 Sony POWER SHOT CAMERA
400 Cannon Digit power DIGITAL CAMERA
300 Sony 3G Dual SIM MOBILE
100 Sony LCD 32" TV
Dr.Girija Narasimhan 33
SELECT * FROM Product_alpha;
PID PNAME PCATEGORY
---------- ----------------------------- --------------------
300 Sony 3G Dual SIM MOBILE
100 Sony LCD 32" TV
it merely updates the data dictionary to indicate that the
pcategoy_AE partition no longer belongs to the
Product_alpha table.
It also remove the partition values from the table.
LIST PARTITION
34Dr.Girija Narasimhan
Dr.Girija Narasimhan 35
The syntax of list partition is three parts:
1) partition method: Partition by list
2) Specify the partition column, example (slocation)
3) Partition description: Partition “partition_name” values (list of values)
list partition is organizing the data allows unordered and unrelated
sets of data to be grouped and organized together.
It is controls each and every row values and mapping with partition
CREATE TABLE STORE_LIST(
STORENO NUMBER(5)PRIMARY KEY,STORENAME VARCHAR2(20),
SPROFIT NUMBER(5),SLOCATION VARCHAR2(15),SDATE DATE)
PARTITION BY LIST (SLOCATION)
(
PARTITION LOC_Muscat VALUES(‘Al-khuwair’,’Ruwi’),
PARTITION LOC_Al Batinah VALUES(‘Barka’, ‘Musannah’),
PARTITION LOC_Dakhliyah VALUES(‘Nizwa’,’ Sumail’));
Dr.Girija Narasimhan 36
SELECT * FROM STORE_LIST;
STORENO STORENAME SPROFIT SLOCATION SDATE
-----------------------------------------------------------
11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09
13 SPENCER PLAZA 6000 Nizwa 18-DEC-05
12 RELIANCE FRESH 4500 Barka 12-SEP-07
15 Apollo Medical 3000 Musanna 21-JUN-06
14 Apollo Medical 8000 Ruwi 24-DEC-08
SELECT * FROM STORE_LIST PARTITION(LOC_Muscat);
STORENO STORENAME SPROFIT SLOCATION SDATE
-----------------------------------------------------------
11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09
14 Apollo Medical 8000 Ruwi 24-DEC-08
SELECT * FROM STORE_LIST PARTITION(LOC_Al_Batinah);
STORENO STORENAME SPROFIT SLOCATION SDATE
-----------------------------------------------------------
12 RELIANCE FRESH 4500 Barka 12-SEP-07
15 Apollo Medical 3000 Musanna 21-JUN-06
SELECT * FROM STORE_LIST PARTITION(LOC_Dakhliyah);
STORENO STORENAME SPROFIT SLOCATION SDATE
-----------------------------------------------------------
13 SPENCER PLAZA 6000 Nizwa 18-DEC-05
LIST PARTITION
ADD PARTITION USING “DEFAULT” VALUE
37Dr.Girija Narasimhan
Dr.Girija Narasimhan 38
The special capability of list partition is default partition.
The benefit of using default partition is, it don’t generate an
error suppose all rows don’t map with any partition in the list.
Using alter table statement, it is possible to add new partition
in the already existed list partition.
ALTER TABLE STORE_LIST
ADD PARTITION LOC_OTHER
VALUES(DEFAULT)TABLESPACE PART4;
INSERT INTO STORE_LIST VALUES(16,'SPENCER PLAZA',4300,
‘Salalah',’29-MAY-2004’);
SELECT * FROM STORE_LIST PARTITION(LOC_OTHER);
STORENO STORENAME SPROFIT SLOCATION SDATE
-------- -------------- -------- ---------- --------
16 SPENCER PLAZA 4300 Salalah 29-MAY-04
ALTER TABLE
MODIFY PARTITION
ADD “List values”
39Dr.Girija Narasimhan
Dr.Girija Narasimhan 40
ALTER TABLE <table Name> MODIFY PARTITION
ADD “List values”
It will add new values in the already existing
partition.
Like update statement, it will change the
specific values of the table
DROP “List values”
Remove the specific value from the already
existing partition.
Like delete statement, how it will delete
specific information from the table.
Values of the partition
Dr.Girija Narasimhan 41
ALTER TABLE STORE_LIST MODIFY PARTITION LOC_Muscat
ADD VALUES (' Bowsher ', ' Seeb ');
INSERT INTO STORE_LIST VALUES(17,'SPENCER PLAZA',3300, 'seeb',’02-APR-2004’);
SELECT * FROM STORE_LIST PARTITION(LOC_Muscat);
STORENO STORENAME SPROFIT SLOCATION SDATE
---------- -------------------- ------------- ------------------ -------------
11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09
14 Apollo Medical 8000 Ruwi 24-DEC-08
17 SPENCER PLAZA 3300 seeb 02-APR-04
In the list partition “LOC_MUSCAT” partition had values “SEEB,
BOWSHER”.
Suppose to change already existed list value in the list partition,
use ALTER TABLE –MODIFY statement to change the new values.
ALTER TABLE
MODIFY PARTITION
DROP “List values”
42Dr.Girija Narasimhan
Dr.Girija Narasimhan 43
Suppose to remove particular list value from the partition, that
partition has the specific values then oracle trigger the error.
The partition doesn’t have that values or data then error free.
Avoiding the error message, first delete the specific values in the
partition and then drop the values from the list partition.
ALTER TABLE STORE_LIST
MODIFY PARTITION LOC_Muscat
DROP VALUES(‘Ruwi’);
ERROR at line 1:
ORA-14518: partition contains rows corresponding to values being
dropped
Delete from store_list where storeno=14
ALTER TABLE STORE_LIST
MODIFY PARTITION LOC_Muscat
DROP VALUES (‘Ruwi’);
TRUNCATE PARTITION
44Dr.Girija Narasimhan
Dr.Girija Narasimhan 45
Truncate statement delete all the values in the mentioned partition.
So, partition which is truncated is empty or without any value. So
error don’t occur like drop values.
But it will retain the Partition without values.
Alter table STORE_LIST truncate partition LOC_Muscat DROP STORAGE;
select * from store_list;
STORENO STORENAME SPROFIT SLOCATION SDATE
---------- -------------------- ---------- --------------------------
13 SPENCER PLAZA 6000 Nizwa 18-DEC-05
12 RELIANCE FRESH 4500 Barka 12-SEP-07
15 Apollo Medical 3000 Musanna 21-JUN-06
16 SPENCER PLAZA 4300 Salalah 29-MAY-04
MOVE PARTITION
46Dr.Girija Narasimhan
Dr.Girija Narasimhan 47
ALTER TABLE products MOVE PARTITION PARTNO1 TABLESPACE
uwdata;
select tablespace_name,partition_name from
user_tab_partitions where table_name='PRODUCTS';
TABLESPACE_NAME PARTITION_NAME
------------------------------ ------------------------
UWDATA PARTNO1
PART2 PARTNO2
PART3 PARTNO3
select tablespace_name,partition_name from
user_tab_partitions where table_name='PRODUCTS';
TABLESPACE_NAME PARTITION_NAME
------------------------------ ------------------------
PART1 PARTNO1
PART2 PARTNO2
PART3 PARTNO3
Here tablespace name is case sensitive. Now “PARTNO1” partition is moved
from tablespace “PART1” to “UMDATA”.
It will move the most active partition to a tablespace. It also create new segment for
the tablespace for the moving partition and it also drops the moved partition's
Previous segment.
SPLIT PARTITION
48Dr.Girija Narasimhan
Dr.Girija Narasimhan 49
It splits the partition into more than one and also move the
specified values into corresponding split partition
SELECT * FROM STORE_LIST PARTITION(LOC_OTHER);
STORENO STORENAME SPROFIT SLOCATION SDATE
--------------------------------- -------------------------
16 SPENCER PLAZA 4300 Salalah 29-MAY-04
18 Apollo Medical 8000 Ibra 24-DEC-08
19 Apollo Medical 3000 Ibra 21-JUN-06
20 SPENCER PLAZA 4300 Shinas 29-MAY-04
21 SPENCER PLAZA 4300 Amrath 29-MAY-04
ALTER TABLE STORE_LIST
SPLIT PARTITION LOC_OTHER VALUES('Ibra')
INTO (PARTITION LOC_Ibra,PARTITION LOC_OTHER);
Dr.Girija Narasimhan 50
SELECT * FROM STORE_LIST PARTITION(LOC_Ibra);
STORENO STORENAME SPROFIT SLOCATION SDATE
---------- ------------------------------------------------
18 Apollo Medical 8000 Ibra 24-DEC-08
19 Apollo Medical 3000 Ibra 21-JUN-06
SELECT * FROM STORE_LIST PARTITION(LOC_OTHER);
STORENO STORENAME SPROFIT SLOCATION SDATE
---------- ------------------------------------------------
16 SPENCER PLAZA 4300 Salalah 29-MAY-04
20 SPENCER PLAZA 4300 Shinas 29-MAY-04
21 SPENCER PLAZA 4300 Amrath 29-MAY-04
HASH PARTITION
51Dr.Girija Narasimhan
Dr.Girija Narasimhan 52
Hash partition is using hashing algorithm.
The key feature of hashing algorithm into it evenly distributes rows
among partitions, so all the partitions are almost the same size.
This feature is useful for spreading the data into sufficient number of
devices to maximizing the I/O devices.
The oracle database uses a linear hashing algorithm.
Suppose any add or merge a hashed partition, the oracle
automatically rearranges the rows within the partition and sub
partition.
Dr.Girija Narasimhan 53
CREATE TABLE products(partno NUMBER,
description VARCHAR2 (60))
PARTITION BY HASH (partno)
(PARTITION partno1 TABLESPACE part1,
PARTITION partno2 TABLESPACE part2,
PARTITION partno3 TABLESPACE part3,
PARTITION partno4 TABLESPACE part4);
Insert into products values(11,’ice cream’);
Insert into products values(12,’coffee’);
Insert into products values(13,’tea’);
Insert into products values(14,’sugar’);
Dr.Girija Narasimhan 54
SELECT * FROM products partition(partno1);
PARTNO DESCRIPTION
---------- ------------------------------------
11 ice cream
13 tea
SELECT * FROM products partition(partno2);
PARTNO DESCRIPTION
---------- -----------------------------------
12 coffee
SELECT * FROM products partition(partno4);
PARTNO DESCRIPTION
---------- -----------------------------------
14 sugar
HASH PARTITION
Using Coalescing
55Dr.Girija Narasimhan
Dr.Girija Narasimhan 56
Select table_name, partition_name from
user_tab_partitions where TABLE_NAME='PRODUCTS';
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------
PRODUCTS PARTNO1
PRODUCTS PARTNO2
PRODUCTS PARTNO3
PRODUCTS PARTNO4
SELECT * FROM products partition(partno4);
PARTNO DESCRIPTION
---------- -------------------------------------------
14 sugar
SELECT * FROM products partition(partno2);
PARTNO DESCRIPTION
---------- --------------------------------------
12 coffee
Dr.Girija Narasimhan 57
Coalescing partitions is a way of reducing
the number partitions in a hash-partitioned
table.
When a hash partition is coalesced, its
contents are redistributed into one or more
remaining partitions determined by the hash
function.
The specific partition that is coalesced is
selected by oracle, and is dropped after
its contents have been redistributed.
Dr.Girija Narasimhan 58
ALTER TABLE PRODUCTS COALESCE PARTITION;
SQL> Select table_name, partition_name from
user_tab_partitions where TABLE_NAME='PRODUCTS';
TABLE_NAME PARTITION_NAME
------------------------------ ----------------------
PRODUCTS PARTNO1
PRODUCTS PARTNO2
PRODUCTS PARTNO3
SQL> SELECT * FROM products partition(partno2);
PARTNO DESCRIPTION
---------- ------------------------------------------
12 coffee
14 sugar
Here PARTNO4 is dropped and PARTNO4 partition values are distributed into
PARTNO2 partition.
Compare
Truncate, Drop list values, Drop,Coalsec
59Dr.Girija Narasimhan
Dr.Girija Narasimhan 60
Truncate
Partition
Drop Partition
coalesce
Drop List value
It retains the
partition, but
deletes all
values from the
partition or from
the table. So,
partition
without any
value or empty.
It will drop partition and
the values also.
It will delete the
partition and
redistribute the
value to other
partition.
Suppose coalesce
partition p1, then
it will
redistributed the
p1 values or
information to
another partition
p2.
In the List partition, For
example
Loc_Muscat (‘Ruwi’,’Seeb’). I
want to delete only Ruwi
value. Suppose any one
record or row in the partition
have ruwi value.
Step1: delete the record
having ‘ruwi’ value from the
table. otherwise it will give
error.
Step 2: alter table modify
partition drop values (ruwi) .
COMPOSITE PARTITION
61Dr.Girija Narasimhan
62Dr.Girija Narasimhan
The types of composite partitioning are:
 Composite Range-Range Partitioning
 Composite Range-Hash Partitioning
 Composite Range-List Partitioning
 Composite List-Range Partitioning
 Composite List-Hash Partitioning
 Composite List-List Partitioning
 Composite Hash-Hash Partitioning
 Composite Hash-List Partitioning
 Composite Hash-Range Partitioning
Composite partitioning is a combination of the two partition method. Table is partitioned by
one data distribution method for example Range Partition. Each partition is further
subdivided into another Partition method for example List.
63Dr.Girija Narasimhan
Conn hr/hr
CREATE TABLE STORE_COMPOSITLIST(
STORENO NUMBER(5)PRIMARY KEY,STORENAME VARCHAR2(20),
SPROFIT NUMBER(5),SLOCATION VARCHAR2(15),SDATE DATE)
PARTITION BY RANGE(STORENO)
SUBPARTITION BY LIST (SLOCATION)
SUBPARTITION TEMPLATE(
SUBPARTITION LOC_Muscat VALUES (‘Al-khuwair’,’Ruwi’) TABLESPACE part1
SUBPARTITION LOC_Dakhliyah VALUES (‘Nizwa’,’Sumail’)TABLESPACE part1)
(
partition p1 values less than(13),
partition p2 values less than(maxvalue));
Composite Partitioned Table - By
Range And List
CREATE TABLESPACE part1
DATAFILE 'c:temppart1.dbf' SIZE 40M
BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K
SEGMENT SPACE MANAGEMENT AUTO ONLINE;
Conn sys as sysdba
sys
Dr.Girija Narasimhan 64
• Partition Type : RANGE
• Partition Key column: STORENO
• Sub partition Type: LIST
• Sub partition key column : SLOCATION
• Sub partition: LOC_Muscat , LOC_Dakhliyah
• Sub partition Values :
LOC_Muscat VALUES (‘Al-khuwair’,’Ruwi’)
LOC_Dakhliyah VALUES (‘Nizwa’,’Sumail’)
• Partition Name and Values: p1 (value <13), p2 (Maxvalue)
Components of composite partition
Dr.Girija Narasimhan 65
set linesize 450;
SELECT table_name, partition_name, composite, high_value
FROM user_tab_partitions;
insert into store_compositlist values(11,'Reliance Fresh',500,'Al-khuwair','10-apr-17');
insert into store_compositlist values(12,'Reliance Fresh',450,'Sumail','12-sep-17');
insert into store_compositlist values(13,'Spencer Plaza',600,'Nizwa','11-Nov-17');
insert into store_compositlist values(14, 'Apollo Medical',300,'Ruwi','21-Jun-17');
insert into store_compositlist values(15,'Apollo Medical',800,'Ruwi','27-may-17');
Display the partition Information
Dr.Girija Narasimhan 66
SELECT table_name, partition_name, subpartition_name,
num_rows FROM user_tab_subpartitions;
Display the sub partition information
Here Num_rows column is empty. For getting values in the Num_rows column analyze the
statistics.
Dr.Girija Narasimhan 67
Display the Partition values in the partition P1 and P2
Dr.Girija Narasimhan 68
Display the Sub Partition values, don’t give sub partition name, then it will give error
message. <partition name> _<subpartition name> in the select statement
69Dr.Girija Narasimhan
PARTITIONED INDEX
Dr.Girija Narasimhan 70
Local Partitioned Index
Global Partitioned Index
Partitioned Indexes
Dr.Girija Narasimhan
71
Partitioned Indexes
Local Index Global Index
one-to-one mapping between a index
partition and a table partition
(equipartitioned)
created with the LOCAL keyword and support
partition independence
one-to-many relationship, allowing one index
partition to map to many table partitions
number of index partitions will match the
number of partitions in the base table.
index partition gets deleted when the
underlying table partition dropped, can’t
drop partition index
Drop a non-empty global index partition will
cause the next highest partition to be marked
unusable.
Column mentioned in the partition index is
not primary key column but it must be “NOT
NULL” column.
Local Non-Prefixed
Indexes
Local Prefixed Indexes
indexed column does not
match the partition key
indexed column match
the partition key
At least one partition should have MAX
VALUE
Global Index don’t have Non-
prefixed Indexes
Dr.Girija Narasimhan 72
CREATE INDEX <index_name>
ON <table_name> <column_name_list>
LOCAL
Partition(partition name);
The primary key column not allowed for indexing
Same partition name as given in the
table.
Local Index
Dr.Girija Narasimhan 73
Local
Prefixed
Indexes
Dr.Girija Narasimhan 74
Local Non-
Prefixed
Indexes
Display the Status of the partition index
Dr.Girija Narasimhan 75
Dropping the Partition from the Local index is not allowed.
Instead of dropping from index, drop the partition from the table, it automatically drop
the partition from the index.
Dr.Girija Narasimhan 76
Global Index
In the global
index max
value should
be include in
partition.
Dr.Girija Narasimhan 77
Display the status of the global index
Unlike local index, it is possible to remove or drop partition from the global index
Dr.Girija Narasimhan 78
Entire global index can’t be rebuild, only specific partition to be rebuild is possible.
Partition name actual name given in
the index no need to mention
indexname_partition name.
Dr.Girija Narasimhan 79
https://www.morganslibrary.org/reference/partitions.html#rlp
http://www.acehints.com/2011/06/global-index-vs-local-index-difference.html
https://oracle-base.com/articles/8i/partitioned-tables-and-indexes
References

More Related Content

PDF
Partitioning tables and indexing them
PDF
Partitioning Tables and Indexing Them --- Article
PPTX
Getting Started with MySQL I
PPTX
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
PPSX
Oracle Table Partitioning - Introduction
PDF
SAS cheat sheet
PPTX
Getting Started with MySQL II
PPT
Data Match Merging in SAS
Partitioning tables and indexing them
Partitioning Tables and Indexing Them --- Article
Getting Started with MySQL I
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
Oracle Table Partitioning - Introduction
SAS cheat sheet
Getting Started with MySQL II
Data Match Merging in SAS

What's hot (20)

PPT
Understanding SAS Data Step Processing
PPTX
Data Warehouse and Business Intelligence - Recipe 1
PDF
Trivadis TechEvent 2017 SQL Server 2016 Temporal Tables by Willfried Färber
PDF
Sas cheat
PPT
Sas-training-in-mumbai
PPTX
Data Warehouse and Business Intelligence - Recipe 3
PDF
Introduction to SAS Data Set Options
PPT
SQL Server 2008 Performance Enhancements
PPTX
New T-SQL Features in SQL Server 2012
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
PPTX
SQL Server Learning Drive
PPTX
Oracle basic queries
ODP
BIS06 Physical Database Models
PPTX
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
PPT
SAS Proc SQL
PDF
MIS5101 WK10 Outcome Measures
PPTX
DDL,DML,SQL Functions and Joins
PDF
ETL Patterns with Postgres
PPTX
Oracle Data Redaction
PPT
Base SAS Statistics Procedures
Understanding SAS Data Step Processing
Data Warehouse and Business Intelligence - Recipe 1
Trivadis TechEvent 2017 SQL Server 2016 Temporal Tables by Willfried Färber
Sas cheat
Sas-training-in-mumbai
Data Warehouse and Business Intelligence - Recipe 3
Introduction to SAS Data Set Options
SQL Server 2008 Performance Enhancements
New T-SQL Features in SQL Server 2012
MySQL Replication Evolution -- Confoo Montreal 2017
SQL Server Learning Drive
Oracle basic queries
BIS06 Physical Database Models
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
SAS Proc SQL
MIS5101 WK10 Outcome Measures
DDL,DML,SQL Functions and Joins
ETL Patterns with Postgres
Oracle Data Redaction
Base SAS Statistics Procedures
Ad

Similar to OER UNIT 4 PARTITION (20)

PDF
Sql for dbaspresentation
PPTX
Ground Breakers Romania: Explain the explain_plan
PPTX
Introduction to Oracle Database.pptx
PDF
Sap abap material
PPTX
Part3 Explain the Explain Plan
PDF
Basics on SQL queries
PDF
Oracle Database File Mapping for Oracle ASM Files
PDF
Oracle Database File Mapping for Oracle ASM Files
PPTX
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
PDF
w_dzon05
PPT
Stack It And Unpack It
PPTX
MySQL Indexes
DOCX
Oracle 11g SQL Overview
PDF
Page Cache in Linux 2.6.pdf
PPTX
vFabric SQLFire Introduction
PPT
15 Ways to Kill Your Mysql Application Performance
PDF
SAS Commands
PPTX
Sql server lesson5
PPT
Less08 Schema
PPTX
Sql server lesson7
Sql for dbaspresentation
Ground Breakers Romania: Explain the explain_plan
Introduction to Oracle Database.pptx
Sap abap material
Part3 Explain the Explain Plan
Basics on SQL queries
Oracle Database File Mapping for Oracle ASM Files
Oracle Database File Mapping for Oracle ASM Files
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
w_dzon05
Stack It And Unpack It
MySQL Indexes
Oracle 11g SQL Overview
Page Cache in Linux 2.6.pdf
vFabric SQLFire Introduction
15 Ways to Kill Your Mysql Application Performance
SAS Commands
Sql server lesson5
Less08 Schema
Sql server lesson7
Ad

More from Girija Muscut (20)

PPTX
Tamil Nalvar
PPTX
Visualization using Tableau
PDF
Introduction to ml
PDF
Effective Visualization with Tableau
PPTX
Guruvayoor song with audio-Udayasthamana puja
PPTX
Lakshmi lalli with audio
PPTX
Bagyada laskhmi purandara dasa
PPTX
Lakshmi lalli
PPTX
Amba nee irangaayenil - papanasam sivan song
PPTX
Mahalakshmi jagan madha - papanasm sivan tamil song
PDF
Sowbhagayaha laskhmi varuvai nee tamil song
PPTX
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
PPTX
Rama Nama Bhajan
PPTX
Saratha devi song 1
PPTX
Saraswathi bhajan 1 with tamil meaning
PPTX
Aneyu karadare -Purandara Dasar.
PDF
Maithriam Bhajatha with tamil meaning (lyrics)
PPTX
Unit 4 scd2-exercise 1-solution
PPTX
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
PPTX
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
Tamil Nalvar
Visualization using Tableau
Introduction to ml
Effective Visualization with Tableau
Guruvayoor song with audio-Udayasthamana puja
Lakshmi lalli with audio
Bagyada laskhmi purandara dasa
Lakshmi lalli
Amba nee irangaayenil - papanasam sivan song
Mahalakshmi jagan madha - papanasm sivan tamil song
Sowbhagayaha laskhmi varuvai nee tamil song
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
Rama Nama Bhajan
Saratha devi song 1
Saraswathi bhajan 1 with tamil meaning
Aneyu karadare -Purandara Dasar.
Maithriam Bhajatha with tamil meaning (lyrics)
Unit 4 scd2-exercise 1-solution
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update

Recently uploaded (20)

PPTX
Computer Software - Technology and Livelihood Education
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
Time Tracking Features That Teams and Organizations Actually Need
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Computer Software - Technology and Livelihood Education
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Patient Appointment Booking in Odoo with online payment
MCP Security Tutorial - Beginner to Advanced
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Why Generative AI is the Future of Content, Code & Creativity?
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
CCleaner 6.39.11548 Crack 2025 License Key
"Secure File Sharing Solutions on AWS".pptx
Computer Software and OS of computer science of grade 11.pptx
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
Salesforce Agentforce AI Implementation.pdf
Wondershare Recoverit Full Crack New Version (Latest 2025)
Time Tracking Features That Teams and Organizations Actually Need
Weekly report ppt - harsh dattuprasad patel.pptx
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf

OER UNIT 4 PARTITION

  • 1. Data warehouse Design Using Oracle https://www.oercommons.org/authorin g/edit/21861 Dr. Girija Narasimhan 1 OER- UNIT 4 PARTITION
  • 3. Oracle Database allocates logical space for all data in the database. The logical units of database space allocation are data blocks, extents, segments, and tablespaces. At a physical level, the data is stored in data files on disk The data in the data files is stored in operating system blocks. 3Dr.Girija Narasimhan
  • 4. Data blocks are the smallest units storing data in the oracle database An extent is a set of logically contiguous data blocks allocated for storing a specific type of information A segment is a set of extents allocated for a specific database object, such as a table. Each segment belongs to one and only one tablespace 4Dr.Girija Narasimhan
  • 5. The database has one or more table space. Table space is called as logical storage unit within an oracle database. The meaning of logical is table space is not visible in the file system. Table space has at least had one data file. Each table space has unique data file. Each table space is divided into based on the size mentioned in the “Create tablespace” statement. The table space builds the bridge between the oracle database and the file system in which the table’s or index data is stored 5Dr.Girija Narasimhan
  • 6. CREATE TABLESPACE dwuser01a DATAFILE 'c:tempdwuser1a.dbf' SIZE 40M BLOCKSIZE 8192 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K SEGMENT SPACE MANAGEMENT AUTO ONLINE; In the Lab session students are sharing single server, then each user created different dbf file in the c:temp- otherwise “already .dbf” file exist error will occur. For example: ‘c:tempuser1.dbf’. .c:tempuser2.dbf’ 6Dr.Girija Narasimhan
  • 8. Dr.Girija Narasimhan 8 You can drop a tablespace and its contents (the segments contained in the tablespace) from the database if the tablespace and its contents are no longer required Once a tablespace has been dropped, the data in the tablespace is not recoverable. Therefore, make sure that all data contained in a tablespace to be dropped will not be required in the future SQL> drop tablespace ica; This will drop the tablespace only if it is empty
  • 9. Dr.Girija Narasimhan 9 Tablespace is not empty and if you want to drop it anyhow then add the following keyword SQL>drop tablespace ica including contents; This will drop the tablespace even if it is not empty. But the data files will not be deleted you have to use operating system command to delete the files. But If you include data files keyword then, the associated data files will also be deleted from the disk. SQL>drop tablespace ica including contents and datafiles;
  • 10. various types of partition 10Dr.Girija Narasimhan
  • 11. Dr.Girija Narasimhan 11 CREATE TABLE <Table name> RANGE PARTITION LIST PARTITION HASH PARTITION RANGE PARTITION Using Number Values RANGE PARTITION Using Alphabet Values RANGE PARTITION Using DATE Values Partition Type Partition Type Partition Type COMPOSITE PARTITION
  • 13. RANGE PARTITION Using Number Values 13Dr.Girija Narasimhan
  • 14. Dr.Girija Narasimhan 14 create table interval_part(pid number(5) not null, fname varchar2(30), lname varchar2(30) ) partition by range(pid) ( partition p1 values less than(101) ) tablespace dwuser01a; Insert into INTERVAL_PART values(100,’Ali’,’Ahmed’); Insert into INTERVAL_PART values(101,’Zahra’,’Khamis’); PARTITION TYPE PARTITION NAME COLUMN NAME Insert values into the interval_part and check whether the records are storing in the assign partition As per given condition, the maximum value is 100, it will store only the first record only. It will give error message, for the value of product id 101 no partition was assigned
  • 15. Dr.Girija Narasimhan 15 SELECT PARTITION_NAME, TABLESPACE_NAME, HIGH_VALUE FROM USER_TAB_PARTITIONS; PARTITION_NAME TABLESPACE_NAME HIGH_VALUE ----------------------------------------------------------------------------- P1 dwuser01a 101 SELECT * FROM INTERVAL_PART PARTITION(P1); PID FNAME LNAME ---------- --------------- ----------------- 100 Ali Ahmed Insert into interval_part values(101,'zahra','khamis') * ERROR at line 1: ORA-14400: inserted partition key does not map to any partition The USER_TAB_PARTITIONS describes the partition information as name of the partition, tablespace name, storage parameter or value range of the partition . Display the values stored in the partition.
  • 16. RANGE PARTITION Using Alphabet Values 16Dr.Girija Narasimhan
  • 17. Dr.Girija Narasimhan 17 Create table product_alpha(Pid number(4) primary key , pname varchar2(25),pcategory varchar2(20)) PARTITION BY RANGE(pcategory)( Partition pcategoy_ae VALUES LESS THAN(‘F%’) TABLESPACE part1, Partition pcategoy_fl VALUES LESS THAN(‘M%’) TABLESPACE part2, Partition pcategoy_mr VALUES LESS THAN(‘S%’) TABLESPACE part3, Partition pcategoy_sz VALUES LESS THAN(MAXVALUE) TABLESPACE part4); Range partition using partition key based on character based values. This type of partition is useful for based on location name, country and supplier based analysis in the data warehousing. This is the alternative to numeric based values. It will store the values “a,b,c,d,e” It will store the exceed values of all the partition Store each partition in different tablespace
  • 18. Dr.Girija Narasimhan 18 SELECT PARTITION_NAME,TABLESPACE_NAME,HIGH_VALUE FROM USER_TAB_PARTITIONS; PARTITION_NAME TABLESPACE_NAME HIGH_VALUE ----------------------------- -------------------------------- ------------------- PCATEGOY_SZ PART4 MAXVALUE PCATEGOY_AE PART1 'F%' PCATEGOY_FL PART2 'M%' PCATEGOY_MR PART3 'S%‘ Insert into Product_alpha values(100,’Sony LCD 32”’,’TV’); Insert into Product_alpha values(200,’Sony POWER SHOT’,’CAMERA’); Insert into Product_alpha values(300,’Sony 3G Dual SIM’,’MOBILE’); Insert into product_alpha values(400,’Cannon Digit power’,’DIGITAL CAMERA’);
  • 19. Dr.Girija Narasimhan 19 SELECT * FROM Product_alpha PARTITION(PCATEGOY_AE); PID PNAME PCATEGORY ---------- --------------------------- -------------------- 200 Sony POWER SHOT CAMERA 400 Cannon Digit power DIGITAL CAMERA SELECT * FROM Product_alpha PARTITION(PCATEGOY_FL); no rows selected SELECT * FROM Product_alpha PARTITION(PCATEGOY_MR); PID PNAME PCATEGORY ---------- ------------------------- -------------------- 300 Sony 3G Dual SIM MOBILE SELECT * FROM Product_alpha PARTITION(PCATEGOY_SZ); PID PNAME PCATEGORY --------- ------------------------- -------------------- 100 Sony LCD 32” TV
  • 20. RANGE PARTITION Using DATE Values 20Dr.Girija Narasimhan
  • 21. Dr.Girija Narasimhan 21 CREATE TABLE Productrange_date ( Pid number(4) Primary key,pname varchar2(25),expdate date NOT Null) PARTITION BY RANGE(expdate)( PARTITION yr0 VALUES LESS THAN (TO_DATE('01-JAN-2007','DD-MON-YYYY')) TABLESPACE part1, PARTITION yr1 VALUES LESS THAN (TO_DATE('01-JAN-2008','DD-MON-YYYY')) TABLESPACE part2, PARTITION yr2 VALUES LESS THAN (TO_DATE('01-JAN-2009','DD-MON-YYYY')) TABLESPACE part3, PARTITION yr3 VALUES LESS THAN (MAXVALUE) TABLESPACE part4); INSERT INTO Productrange_date VALUES (1001, ‘Orange’, ’21-MAY-08’); INSERT INTO Productrange_date VALUES (1002, ‘Sugar’, ’16-MAY-09’); INSERT INTO Productrange_date VALUES (1003, ‘Biscutt’, ’12-NOV-09’); SQL> select * from productrange_date; PID PNAME EXPDATE ---------- ------------------------- ------------- 1001 Orange 21-MAY-08 1002 Sugar 16-MAY-09 1003 Biscutt 12-NOV-09 The partition key in the range partition to be Date based. It is useful for analyzing table data week wise or day wise. Store values upto 31-dec-2006
  • 22. Dr.Girija Narasimhan 22 SELECT * FROM productrange_date PARTITION(yr1); no rows selected SELECT * FROM productrange_date PARTITION(yr2); PID PNAME EXPDATE ---------- -- ------------- ------------- 1001 Orange 21-MAY-08 SELECT * FROM productrange_date PARTITION(yr3); PID PNAME EXPDATE --------- --------------- ------------- 1002 Sugar 16-MAY-09 1003 Biscutt 12-NOV-09
  • 24. Dr.Girija Narasimhan 24 ALTER TABLE <Table name> ADD PARTITION RANAME PARTITION DROP PARTITION MERGE PARTITION
  • 25. ADD PARTITION Using Alter table – ADD Partition statement, it is possible to insert new partition details of already existed partition Alter table INTERVAL_PART ADD partition p2 values less than(201); SELECT PARTITION_NAME,TABLESPACE_NAME,HIGH_VALUE FROM USER_TAB_PARTITIONS; PARTITION_NAME TABLESPACE_NAME HIGH_VALUE -------------------------- ---------------- ----------------- P1 UWDATA 101 P2 UWDATA 201
  • 26. SELECT * FROM INTERVAL_PART partition(P1); PID FNAME LNAME ---------- ------------------------- -------------- 100 Ali Ahmed SELECT * FROM INTERVAL_PART partition(P2); PID FNAME LNAME ---------- ------------------------- -------------- 101 Zahra Khamis 200 Mohammed Omar Insert into INTERVAL_PART values(101,'zahra','khamis'); Insert into INTERVAL_PART values(200,'Mohammed','omar'); SELECT * FROM INTERVAL_PART; PID FNAME LNAME ---------- ------------------------- -------------- 100 Ali Ahmed 101 Zahra Khamis 200 Mohammed Omar
  • 28. ALTER TABLE INTERVAL_PART RENAME PARTITION P1 TO P9; SQL> SELECT partition_name FROM user_tab_partitions WHERE PARTITION_NAME='P9'; PARTITION_NAME -------------------------- P9 SQL> SELECT * FROM INTERVAL_PART partition(P9); PID FNAME LNAME ---------- -------------- --------------- 100 Ali Ahmed
  • 30. Dr.Girija Narasimhan 30 SELECT * FROM productrange_date PARTITION(yr2); PID PNAME EXPDATE ---------- -- ------------- ------------- 1001 Orange 21-MAY-08 SELECT * FROM productrange_date PARTITION(yr3); PID PNAME EXPDATE --------- --------------- ------------- 1002 Sugar 16-MAY-09 1003 Biscutt 12-NOV-09 Alter table productrange_date merge partitions yr2,yr3 into partition yr6; SELECT * FROM productrange_date PARTITION(yr6) PID PNAME EXPDATE --------- ------------------ --------- 1001 Orange 22-MAY-08 1002 Sugar 16-MAY-09 1003 Biscutt 12-NOV-09 Merge partition creates a new partition called yr6 It copies the values from yr2 and yr3
  • 32. Dr.Girija Narasimhan 32 Alter table Product_alpha drop partition pcategoy_ae; SELECT * FROM Product_alpha PARTITION(PCATEGOY_AE); PID PNAME PCATEGORY ---------- --------------------------- -------------------- 200 Sony POWER SHOT CAMERA 400 Cannon Digit power DIGITAL CAMERA SELECT * FROM Product_alpha; PID PNAME PCATEGORY ---------- ----------------------------- -------------------- 200 Sony POWER SHOT CAMERA 400 Cannon Digit power DIGITAL CAMERA 300 Sony 3G Dual SIM MOBILE 100 Sony LCD 32" TV
  • 33. Dr.Girija Narasimhan 33 SELECT * FROM Product_alpha; PID PNAME PCATEGORY ---------- ----------------------------- -------------------- 300 Sony 3G Dual SIM MOBILE 100 Sony LCD 32" TV it merely updates the data dictionary to indicate that the pcategoy_AE partition no longer belongs to the Product_alpha table. It also remove the partition values from the table.
  • 35. Dr.Girija Narasimhan 35 The syntax of list partition is three parts: 1) partition method: Partition by list 2) Specify the partition column, example (slocation) 3) Partition description: Partition “partition_name” values (list of values) list partition is organizing the data allows unordered and unrelated sets of data to be grouped and organized together. It is controls each and every row values and mapping with partition CREATE TABLE STORE_LIST( STORENO NUMBER(5)PRIMARY KEY,STORENAME VARCHAR2(20), SPROFIT NUMBER(5),SLOCATION VARCHAR2(15),SDATE DATE) PARTITION BY LIST (SLOCATION) ( PARTITION LOC_Muscat VALUES(‘Al-khuwair’,’Ruwi’), PARTITION LOC_Al Batinah VALUES(‘Barka’, ‘Musannah’), PARTITION LOC_Dakhliyah VALUES(‘Nizwa’,’ Sumail’));
  • 36. Dr.Girija Narasimhan 36 SELECT * FROM STORE_LIST; STORENO STORENAME SPROFIT SLOCATION SDATE ----------------------------------------------------------- 11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09 13 SPENCER PLAZA 6000 Nizwa 18-DEC-05 12 RELIANCE FRESH 4500 Barka 12-SEP-07 15 Apollo Medical 3000 Musanna 21-JUN-06 14 Apollo Medical 8000 Ruwi 24-DEC-08 SELECT * FROM STORE_LIST PARTITION(LOC_Muscat); STORENO STORENAME SPROFIT SLOCATION SDATE ----------------------------------------------------------- 11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09 14 Apollo Medical 8000 Ruwi 24-DEC-08 SELECT * FROM STORE_LIST PARTITION(LOC_Al_Batinah); STORENO STORENAME SPROFIT SLOCATION SDATE ----------------------------------------------------------- 12 RELIANCE FRESH 4500 Barka 12-SEP-07 15 Apollo Medical 3000 Musanna 21-JUN-06 SELECT * FROM STORE_LIST PARTITION(LOC_Dakhliyah); STORENO STORENAME SPROFIT SLOCATION SDATE ----------------------------------------------------------- 13 SPENCER PLAZA 6000 Nizwa 18-DEC-05
  • 37. LIST PARTITION ADD PARTITION USING “DEFAULT” VALUE 37Dr.Girija Narasimhan
  • 38. Dr.Girija Narasimhan 38 The special capability of list partition is default partition. The benefit of using default partition is, it don’t generate an error suppose all rows don’t map with any partition in the list. Using alter table statement, it is possible to add new partition in the already existed list partition. ALTER TABLE STORE_LIST ADD PARTITION LOC_OTHER VALUES(DEFAULT)TABLESPACE PART4; INSERT INTO STORE_LIST VALUES(16,'SPENCER PLAZA',4300, ‘Salalah',’29-MAY-2004’); SELECT * FROM STORE_LIST PARTITION(LOC_OTHER); STORENO STORENAME SPROFIT SLOCATION SDATE -------- -------------- -------- ---------- -------- 16 SPENCER PLAZA 4300 Salalah 29-MAY-04
  • 39. ALTER TABLE MODIFY PARTITION ADD “List values” 39Dr.Girija Narasimhan
  • 40. Dr.Girija Narasimhan 40 ALTER TABLE <table Name> MODIFY PARTITION ADD “List values” It will add new values in the already existing partition. Like update statement, it will change the specific values of the table DROP “List values” Remove the specific value from the already existing partition. Like delete statement, how it will delete specific information from the table. Values of the partition
  • 41. Dr.Girija Narasimhan 41 ALTER TABLE STORE_LIST MODIFY PARTITION LOC_Muscat ADD VALUES (' Bowsher ', ' Seeb '); INSERT INTO STORE_LIST VALUES(17,'SPENCER PLAZA',3300, 'seeb',’02-APR-2004’); SELECT * FROM STORE_LIST PARTITION(LOC_Muscat); STORENO STORENAME SPROFIT SLOCATION SDATE ---------- -------------------- ------------- ------------------ ------------- 11 RELIANCE FRESH 5000 Al-khuwair 10-APR-09 14 Apollo Medical 8000 Ruwi 24-DEC-08 17 SPENCER PLAZA 3300 seeb 02-APR-04 In the list partition “LOC_MUSCAT” partition had values “SEEB, BOWSHER”. Suppose to change already existed list value in the list partition, use ALTER TABLE –MODIFY statement to change the new values.
  • 42. ALTER TABLE MODIFY PARTITION DROP “List values” 42Dr.Girija Narasimhan
  • 43. Dr.Girija Narasimhan 43 Suppose to remove particular list value from the partition, that partition has the specific values then oracle trigger the error. The partition doesn’t have that values or data then error free. Avoiding the error message, first delete the specific values in the partition and then drop the values from the list partition. ALTER TABLE STORE_LIST MODIFY PARTITION LOC_Muscat DROP VALUES(‘Ruwi’); ERROR at line 1: ORA-14518: partition contains rows corresponding to values being dropped Delete from store_list where storeno=14 ALTER TABLE STORE_LIST MODIFY PARTITION LOC_Muscat DROP VALUES (‘Ruwi’);
  • 45. Dr.Girija Narasimhan 45 Truncate statement delete all the values in the mentioned partition. So, partition which is truncated is empty or without any value. So error don’t occur like drop values. But it will retain the Partition without values. Alter table STORE_LIST truncate partition LOC_Muscat DROP STORAGE; select * from store_list; STORENO STORENAME SPROFIT SLOCATION SDATE ---------- -------------------- ---------- -------------------------- 13 SPENCER PLAZA 6000 Nizwa 18-DEC-05 12 RELIANCE FRESH 4500 Barka 12-SEP-07 15 Apollo Medical 3000 Musanna 21-JUN-06 16 SPENCER PLAZA 4300 Salalah 29-MAY-04
  • 47. Dr.Girija Narasimhan 47 ALTER TABLE products MOVE PARTITION PARTNO1 TABLESPACE uwdata; select tablespace_name,partition_name from user_tab_partitions where table_name='PRODUCTS'; TABLESPACE_NAME PARTITION_NAME ------------------------------ ------------------------ UWDATA PARTNO1 PART2 PARTNO2 PART3 PARTNO3 select tablespace_name,partition_name from user_tab_partitions where table_name='PRODUCTS'; TABLESPACE_NAME PARTITION_NAME ------------------------------ ------------------------ PART1 PARTNO1 PART2 PARTNO2 PART3 PARTNO3 Here tablespace name is case sensitive. Now “PARTNO1” partition is moved from tablespace “PART1” to “UMDATA”. It will move the most active partition to a tablespace. It also create new segment for the tablespace for the moving partition and it also drops the moved partition's Previous segment.
  • 49. Dr.Girija Narasimhan 49 It splits the partition into more than one and also move the specified values into corresponding split partition SELECT * FROM STORE_LIST PARTITION(LOC_OTHER); STORENO STORENAME SPROFIT SLOCATION SDATE --------------------------------- ------------------------- 16 SPENCER PLAZA 4300 Salalah 29-MAY-04 18 Apollo Medical 8000 Ibra 24-DEC-08 19 Apollo Medical 3000 Ibra 21-JUN-06 20 SPENCER PLAZA 4300 Shinas 29-MAY-04 21 SPENCER PLAZA 4300 Amrath 29-MAY-04 ALTER TABLE STORE_LIST SPLIT PARTITION LOC_OTHER VALUES('Ibra') INTO (PARTITION LOC_Ibra,PARTITION LOC_OTHER);
  • 50. Dr.Girija Narasimhan 50 SELECT * FROM STORE_LIST PARTITION(LOC_Ibra); STORENO STORENAME SPROFIT SLOCATION SDATE ---------- ------------------------------------------------ 18 Apollo Medical 8000 Ibra 24-DEC-08 19 Apollo Medical 3000 Ibra 21-JUN-06 SELECT * FROM STORE_LIST PARTITION(LOC_OTHER); STORENO STORENAME SPROFIT SLOCATION SDATE ---------- ------------------------------------------------ 16 SPENCER PLAZA 4300 Salalah 29-MAY-04 20 SPENCER PLAZA 4300 Shinas 29-MAY-04 21 SPENCER PLAZA 4300 Amrath 29-MAY-04
  • 52. Dr.Girija Narasimhan 52 Hash partition is using hashing algorithm. The key feature of hashing algorithm into it evenly distributes rows among partitions, so all the partitions are almost the same size. This feature is useful for spreading the data into sufficient number of devices to maximizing the I/O devices. The oracle database uses a linear hashing algorithm. Suppose any add or merge a hashed partition, the oracle automatically rearranges the rows within the partition and sub partition.
  • 53. Dr.Girija Narasimhan 53 CREATE TABLE products(partno NUMBER, description VARCHAR2 (60)) PARTITION BY HASH (partno) (PARTITION partno1 TABLESPACE part1, PARTITION partno2 TABLESPACE part2, PARTITION partno3 TABLESPACE part3, PARTITION partno4 TABLESPACE part4); Insert into products values(11,’ice cream’); Insert into products values(12,’coffee’); Insert into products values(13,’tea’); Insert into products values(14,’sugar’);
  • 54. Dr.Girija Narasimhan 54 SELECT * FROM products partition(partno1); PARTNO DESCRIPTION ---------- ------------------------------------ 11 ice cream 13 tea SELECT * FROM products partition(partno2); PARTNO DESCRIPTION ---------- ----------------------------------- 12 coffee SELECT * FROM products partition(partno4); PARTNO DESCRIPTION ---------- ----------------------------------- 14 sugar
  • 56. Dr.Girija Narasimhan 56 Select table_name, partition_name from user_tab_partitions where TABLE_NAME='PRODUCTS'; TABLE_NAME PARTITION_NAME ------------------------------ ------------------------ PRODUCTS PARTNO1 PRODUCTS PARTNO2 PRODUCTS PARTNO3 PRODUCTS PARTNO4 SELECT * FROM products partition(partno4); PARTNO DESCRIPTION ---------- ------------------------------------------- 14 sugar SELECT * FROM products partition(partno2); PARTNO DESCRIPTION ---------- -------------------------------------- 12 coffee
  • 57. Dr.Girija Narasimhan 57 Coalescing partitions is a way of reducing the number partitions in a hash-partitioned table. When a hash partition is coalesced, its contents are redistributed into one or more remaining partitions determined by the hash function. The specific partition that is coalesced is selected by oracle, and is dropped after its contents have been redistributed.
  • 58. Dr.Girija Narasimhan 58 ALTER TABLE PRODUCTS COALESCE PARTITION; SQL> Select table_name, partition_name from user_tab_partitions where TABLE_NAME='PRODUCTS'; TABLE_NAME PARTITION_NAME ------------------------------ ---------------------- PRODUCTS PARTNO1 PRODUCTS PARTNO2 PRODUCTS PARTNO3 SQL> SELECT * FROM products partition(partno2); PARTNO DESCRIPTION ---------- ------------------------------------------ 12 coffee 14 sugar Here PARTNO4 is dropped and PARTNO4 partition values are distributed into PARTNO2 partition.
  • 59. Compare Truncate, Drop list values, Drop,Coalsec 59Dr.Girija Narasimhan
  • 60. Dr.Girija Narasimhan 60 Truncate Partition Drop Partition coalesce Drop List value It retains the partition, but deletes all values from the partition or from the table. So, partition without any value or empty. It will drop partition and the values also. It will delete the partition and redistribute the value to other partition. Suppose coalesce partition p1, then it will redistributed the p1 values or information to another partition p2. In the List partition, For example Loc_Muscat (‘Ruwi’,’Seeb’). I want to delete only Ruwi value. Suppose any one record or row in the partition have ruwi value. Step1: delete the record having ‘ruwi’ value from the table. otherwise it will give error. Step 2: alter table modify partition drop values (ruwi) .
  • 62. 62Dr.Girija Narasimhan The types of composite partitioning are:  Composite Range-Range Partitioning  Composite Range-Hash Partitioning  Composite Range-List Partitioning  Composite List-Range Partitioning  Composite List-Hash Partitioning  Composite List-List Partitioning  Composite Hash-Hash Partitioning  Composite Hash-List Partitioning  Composite Hash-Range Partitioning Composite partitioning is a combination of the two partition method. Table is partitioned by one data distribution method for example Range Partition. Each partition is further subdivided into another Partition method for example List.
  • 63. 63Dr.Girija Narasimhan Conn hr/hr CREATE TABLE STORE_COMPOSITLIST( STORENO NUMBER(5)PRIMARY KEY,STORENAME VARCHAR2(20), SPROFIT NUMBER(5),SLOCATION VARCHAR2(15),SDATE DATE) PARTITION BY RANGE(STORENO) SUBPARTITION BY LIST (SLOCATION) SUBPARTITION TEMPLATE( SUBPARTITION LOC_Muscat VALUES (‘Al-khuwair’,’Ruwi’) TABLESPACE part1 SUBPARTITION LOC_Dakhliyah VALUES (‘Nizwa’,’Sumail’)TABLESPACE part1) ( partition p1 values less than(13), partition p2 values less than(maxvalue)); Composite Partitioned Table - By Range And List CREATE TABLESPACE part1 DATAFILE 'c:temppart1.dbf' SIZE 40M BLOCKSIZE 8192 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K SEGMENT SPACE MANAGEMENT AUTO ONLINE; Conn sys as sysdba sys
  • 64. Dr.Girija Narasimhan 64 • Partition Type : RANGE • Partition Key column: STORENO • Sub partition Type: LIST • Sub partition key column : SLOCATION • Sub partition: LOC_Muscat , LOC_Dakhliyah • Sub partition Values : LOC_Muscat VALUES (‘Al-khuwair’,’Ruwi’) LOC_Dakhliyah VALUES (‘Nizwa’,’Sumail’) • Partition Name and Values: p1 (value <13), p2 (Maxvalue) Components of composite partition
  • 65. Dr.Girija Narasimhan 65 set linesize 450; SELECT table_name, partition_name, composite, high_value FROM user_tab_partitions; insert into store_compositlist values(11,'Reliance Fresh',500,'Al-khuwair','10-apr-17'); insert into store_compositlist values(12,'Reliance Fresh',450,'Sumail','12-sep-17'); insert into store_compositlist values(13,'Spencer Plaza',600,'Nizwa','11-Nov-17'); insert into store_compositlist values(14, 'Apollo Medical',300,'Ruwi','21-Jun-17'); insert into store_compositlist values(15,'Apollo Medical',800,'Ruwi','27-may-17'); Display the partition Information
  • 66. Dr.Girija Narasimhan 66 SELECT table_name, partition_name, subpartition_name, num_rows FROM user_tab_subpartitions; Display the sub partition information Here Num_rows column is empty. For getting values in the Num_rows column analyze the statistics.
  • 67. Dr.Girija Narasimhan 67 Display the Partition values in the partition P1 and P2
  • 68. Dr.Girija Narasimhan 68 Display the Sub Partition values, don’t give sub partition name, then it will give error message. <partition name> _<subpartition name> in the select statement
  • 70. Dr.Girija Narasimhan 70 Local Partitioned Index Global Partitioned Index Partitioned Indexes
  • 71. Dr.Girija Narasimhan 71 Partitioned Indexes Local Index Global Index one-to-one mapping between a index partition and a table partition (equipartitioned) created with the LOCAL keyword and support partition independence one-to-many relationship, allowing one index partition to map to many table partitions number of index partitions will match the number of partitions in the base table. index partition gets deleted when the underlying table partition dropped, can’t drop partition index Drop a non-empty global index partition will cause the next highest partition to be marked unusable. Column mentioned in the partition index is not primary key column but it must be “NOT NULL” column. Local Non-Prefixed Indexes Local Prefixed Indexes indexed column does not match the partition key indexed column match the partition key At least one partition should have MAX VALUE Global Index don’t have Non- prefixed Indexes
  • 72. Dr.Girija Narasimhan 72 CREATE INDEX <index_name> ON <table_name> <column_name_list> LOCAL Partition(partition name); The primary key column not allowed for indexing Same partition name as given in the table. Local Index
  • 74. Dr.Girija Narasimhan 74 Local Non- Prefixed Indexes Display the Status of the partition index
  • 75. Dr.Girija Narasimhan 75 Dropping the Partition from the Local index is not allowed. Instead of dropping from index, drop the partition from the table, it automatically drop the partition from the index.
  • 76. Dr.Girija Narasimhan 76 Global Index In the global index max value should be include in partition.
  • 77. Dr.Girija Narasimhan 77 Display the status of the global index Unlike local index, it is possible to remove or drop partition from the global index
  • 78. Dr.Girija Narasimhan 78 Entire global index can’t be rebuild, only specific partition to be rebuild is possible. Partition name actual name given in the index no need to mention indexname_partition name.