Professional Documents
Culture Documents
: PPT/2K403/02
Schema Management in Oracle 9i
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
2
Types of SQL Statements in Oracle
System Control Statements
Session Control
Data Manipulation
Transaction Control
Data Definition
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
3
System Control Statements
The system control statement alter system is use to alter the
properties of running database instance.
Example, the alter system statement is use to modify certain
initialization parameters such as the shared pool component
of the SGA.
At present, the alter system command is the only system
control statement in Oracle.
Example
SQL> alter system kill session 25,9192;
Session killed
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
4
Session Control Statements
Session control statements dynamically alter the properties of
an individual users session.
Example, you can use alter session set sql trace = true statement
to trace your session SQL statement alone.
Common session control statements include the alter session
and set role commands.
Example
SQL> alter session set nls_date_format = MM-DD-YYYY
HH:MI:SS;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
5
Data Manipulation Statements
The DML statements are the statements that either query or
manipulate data in a table.
Four important DML Statements are :
Select, Insert, Update and Delete
Other DML statements are :
call, lock table, explain plan and merge.
Other DML statements facilitate the execution of the four basic
DML statements.
Example, the merge statement deals with conditional inserts
and deletes, and the lock table statement is used to prevent
other transactions from modifying the same data while a
transaction is still running.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
6
Transaction Control Statements
The transaction control statements are use to control the
changes made when you issue data manipulation SQL
statement such as insert, update and delete.
This rarely used statement denotes the start of transaction. Its
mostly used for specifying a particular rollback segment for use by
a transaction.
Set transaction
This statement allows flexibility in your transactions, helping you
set intermediate points in the transaction to which you can roll back
or undo your transactions.
Save point
When it follows one or more DML statements, this statement will
undo the statements made by the preceding statements.
Rollback
When it follows a set of DML statements, this statement will make
the changes permanent.
Commit
Definition Statement
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
7
Data Definition Statements
DDL statements enable you to define the database.
DDL statements define the structure of the various schema
objects in Oracle.
DDL statements can also alter the structure of the objects and
drop the objects from the database.
The following list presents some of the main uses of the DDL
statements.
Create, alter and drop tables, indexes, procedure, functions and
packages.
Creating and managing users, tablespaces of the database.
Granting and revoking privileges on objects to users.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
8
Oracle Schema Management
A schema is defined as a logical collection of objects, although
it is used mostly as a synonym for a user.
An accounting schema within a company database would have
all the tables and code pertaining to the accounting
department.
Type of schema objects:
Tables, Indexes, Views
Materialized views
Procedures, functions, and packages.
Object tables and object types.
Database triggers
Database Links
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
9
Whats the Dual Table?
The dual table belongs to the sys schema and is created
automatically when the data dictionary is created.
The dual table has one column called dummy and one row.
The dual table enables you to use the Oracle select command
to compute a constant expression.
The dual table serves as a catchall table for expression.
Example
SQL> select 9 * 234 from dual;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
10
Managing Tablespaces
When you create a database, Oracle creates the SYSTEM
tablespace.
All the dictionary objects are stored in this tablespace.
The data files you specify when you create the database are
assigned to the SYSTEM tablespace.
You can add more space to the SYSTEM tablespace after you
create the database by adding more data files or by increasing
the size of the data files.
The PL/SQL program units created in the database are also
stored in the SYSTEM tablespace.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
11
Managing Tablespaces(contd.)
Oracle allocates space to an object in a tablespace, it is
allocated in chunks of contiguous database blocks known as
extents.
Each object is allocated a segment, which has one or more
extents.
Oracle maintains the extent information such as extents free,
extent size, extents allocated, and so on either in the data
dictionary or in the tablespace itself.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
12
Managing Tablespaces(contd.)
It you store the extent management information in the
dictionary for a tablespace, that tablespace is called a
dictionary-managed tablespace.
Whenever an extent is allocated or freed, the information is
updated in the corresponding dictionary tables.
Such updates also generate undo information.
If the storage management information is in the tablespace
itself, it is called locally managed tablespace.
They manage extents by referring to the bitmaps kept in each
data file of a tablespace for all the block within that data file.
Each bit corresponds to a block or a group of blocks.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
13
Managing Tablespaces(contd.)
When an extent is allocated or freed fro reuse, Oracle changes
the bitmap values to show the new status of the blocks.
These changes do not generate rollback information because
they do not generate rollback information because they do not
update tables in the data dictionary.
To create the tablespace use the CREATE TABLESPACE
statement.
Use ALTER TABLESPACE statement to modify the tablespace.
Use DROP TABLESPACE statement to delete the tablespace.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
14
Creating a Tablespace
In dictionary-managed tablespaces, all extent information is
stored in the data dictionary.
This statement creates a tablespace name APP_data, the data
file specified is created with size of 100MB.
CREATE TABLESPACE app_data
DATAFILE /DISK4/app01.dbf SIZE 100M,
EXTENT MANAGEMENT DICTIONARY;
CREATE TABLESPACE app_data
DATAFILE /DISK4/app01.dbf SIZE 100M,
EXTENT MANAGEMENT DICTIONARY;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
15
Creating Tablespaces
The following statement creates a tablespace using all optional
clauses.
CREATE TABLESPACE app_data
DATAFILE /DISK4/app01.dbf SIZE 100M,
Default storage
( initial 256K next 256K minextents 2 pctincrease 0 Maxextents 4096)
Blocksize 4K
Minumum extent 256K
Logging
Online
Permanent
Extent Management Dictionary
Segment Space Management Manual
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
16
Creating Tablespaces( contd.)
DEFAULT STORAGE
Specifies the default storage parameters for new objects that are
created in the tablespace.
Specify defaults parameters within parentheses
No parameter is mandatory, but if you specify default the
DEFAULT STORAGE clause, you must specify at least one
parameter inside the parentheses.
BLOCKSIZE
Specifies the block size that is used for the objects created in the
tablespace.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
17
Creating Tablespaces( contd.)
INITIAL
Specifies the size of the objects first extent.
NEXT
Specifies the size of the segments next and successive extents.
The size is specified in bytes ( K or M )
The defualt value of Initial and Next is 5 database blocks.
The minimum value of Initial is 3 database block for locally
managed tablespaces and 2 database block for dictionary-
managed tablespaces.
Next is 1 database block.
Even if you specify sizes smaller than these values, Oracle
allocates the minimum sizes when creating segments in the
tablespace.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
18
Creating Tablespaces( contd.)
PCTINCREASE
Specifies how much the third and subsequent extents grow over
the preceding extent.
The default value is 50, means that each subsequent extent is 50
percent larger than the preceding extent.
The minimum value is 0, meaning all extents after the first are the
same size.
Example if the storage parameters are (INBITAIL 1M NEXT 2M
PCTINCREASE 0), the extent sizes are 1MB, 2MB, 2MB, 2MB, and
so on.
If PCTINCREASE is 50, the extent sizes are 1MB, 2MB, 3MB,
4.5MB, 6.75MB, and so on
The actual NEXT extent size is rounded to a multiple of the block
size.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
19
Creating Tablespaces( contd.)
MINEXTENTS
Specifies the total number of extents allocated to the segment at
the time of creation.
The default and minimum value is 1.
When you specify MINEXTENTS as more than 1, the extent sizes
are calculated based on NEXT and PCTINCREASE.
MAXEXTENTS
Specifies the maximum number of extents that can be allocated to
a segment.
You can specify an integer or UNLIMITED.
The minimum value is 1.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
20
Creating Tablespaces( contd.)
MINIMUM EXTENT
Specifies that the extent size are a multiple of size specified.
The INITIAL and NEXT extent sizes you specify should be a
multiple of MINIMUM EXTENT.
LOGGING
Specifies that the DDL operations and direct-load INSERT are
recorded in the redo log files.
LOGGING is default, an can be omitted.
When you specify NOLOGGING, data is modified with minimal
logging and hence the commands complete faster.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
21
Creating Tablespaces( contd.)
ONLINE
Specifies that the tablespace be created online or available as
soon as it is created.
Online is default and hence can be omitted.
PERMANENT
Specifies whether the tablespace is to be used to create
permanent objects such as tables, indexes.
PERMANENT is default.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
22
Creating Tablespaces( contd.)
EXTENT MANAGEMENT
Until Oracle 9i, dictionary managed tablespaces were the default.
In Oracle 9i, to create a dictionary-managed tablespace, you need
to explicitly specify the EXTENT MANAGEMENT DICTIONARY
clause.
If omitted, ORACLE creates the tablespace as locally managed.
SEGMENT SPACE MANAGEMENT
This clause is applicable only to locally managed tablespaces.
The valid values are MANUAL and AUTO.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
23
Locally Managed Tablespaces
Reduced recursive space management
Reduced contention on data dictionary tables
No rollback generated ???
No coalescing required
CREATE TABLESPACE user_data
DATAFILE /u1/user_data.dbf SIZE 500M
EXTENT MANAGEMENT LOCAL
UNIFORM SIZE 10M;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
24
Temporary Tablespace
Used for sort operations
Cannot contain any permanent objects
CREATE TABLESPACE sort
DATAFILE /DISK2/sort01.dbf SIZE 50M
MINIMUM EXTENT 1M
DEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 500
PCTINCREASE 0)
TEMPORARY;
CREATE TABLESPACE sort
DATAFILE /DISK2/sort01.dbf SIZE 50M
MINIMUM EXTENT 1M
DEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 500
PCTINCREASE 0)
TEMPORARY;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
25
Undo Tablespace
Oracle 9i can manage undo information automatically.
For automatic undo management, you must have one undo
tablespace.
The undo tablespace can be created using CREATE UNDO
TABLESPACE statement.
When creating undo tablespace, you specify only the EXTENT
MANAGEMENT LOCAL and DATAFILE clause.
Create undo tablespace undo_tbs
datafile /opt/oracle/mydb/undo_tbs01.dbf size 500M;
You can create undo tablespace when creating a database
using the UNDO TABLESPACE clause of the CREATE
DATABASE statement.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
26
Adding Data Files to a Tablespace
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK5/app03.dbf SIZE 200M;
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK5/app03.dbf SIZE 200M;
Tablespace APP_DATA
Tablespace APP_DATA
app03.dbf
2M
app02.dbf
1M
app01.dbf
1M
Example
Example
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
27
Enabling Automatic Extension of Data Files
Example
Example
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK6/app04.dbf SIZE 200M
AUTOEXTEND ON NEXT 10M
MAXSIZE 500M;
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK6/app04.dbf SIZE 200M
AUTOEXTEND ON NEXT 10M
MAXSIZE 500M;
Tablespace APP_ DATA Tablespace APP_ DATA
app04.dbf
2M
app03.dbf
2M
app01.dbf
1M
app02.dbf
1M
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
28
ALTER DATABASE DATAFILE /DISK5/app02.dbf RESIZE
200M;
Example
Changing the Size of Data Files Manually
1M
Tablespace APP_DATA Tablespace APP_DATA
app02.dbf
1M
app01.dbf
1M
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
29
Changing the Storage Settings
Example
ALTER TABLESPACE app_data
MINIMUM EXTENT 2M;
ALTER TABLESPACE app_data
DEFAULT STORAGE
(INITIAL 2M NEXT 2M
MAXEXTENTS 999);
ALTER TABLESPACE app_data
MINIMUM EXTENT 2M;
ALTER TABLESPACE app_data
DEFAULT STORAGE
(INITIAL 2M NEXT 2M
MAXEXTENTS 999);
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
30
OFFLINE Status
The tablespace that is offline is not available for data access.
The SYSTEM tablespace and any tablespace with active
rollback segments cannot be taken offline.
Example
ALTER TABLESPACE app_data OFFLINE;
ALTER TABLESPACE app_data OFFLINE;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
31
Moving Data Files: ALTER TABLESPACE
The tablespace APP_DATA must be offline.
The target data files must exist.
Example
ALTER TABLESPACE app_data RENAME DATAFILE
/DISK4/app01.dbf TO /DISK5/app01.dbf;
ALTER TABLESPACE app_data RENAME DATAFILE
/DISK4/app01.dbf TO /DISK5/app01.dbf;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
32
Moving Data Files: ALTER TABLESPACE ( contd. )
The database must be mounted.
The target data file must exist.
Example
ALTER DATABASE RENAME FILE
/DISK1/system01.dbf TO /DISK2/system01.dbf;
ALTER DATABASE RENAME FILE
/DISK1/system01.dbf TO /DISK2/system01.dbf;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
33
The READ-ONLY Tablespace Status
Example
The tablespace APP_DATA is only available for read
operations.
Objects can be dropped
ALTER TABLESPACE app_data READ ONLY;
ALTER TABLESPACE app_data READ ONLY;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
34
Making Tablespace Read-Only
The tablespace must be online.
No active transactions are allowed (prior to release 8i)
Oracle 8i and higher version allows current transaction to
complete.
The tablespace must not contain active rollback segments.
The tablespace must not currently be involved in an online
backup.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
35
Dropping Tablespaces
The following statement removes the APP_DATA tablespace
and all its contents.
Example
DROP TABLESPACE app_data
INCLUDING CONTENTS;
DROP TABLESPACE app_data
INCLUDING CONTENTS;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
36
Obtaining Tablespace Information
DBA_TABLESPACES (V$TABLESPACE)
TABLESPACE_NAME
NEXT_EXTENT
MAX_EXTENTS
PCT_INCREASE
MIN_EXTLEN
STATUS
CONTENTS
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
37
Oracle Managed Files
The Oracle 9i database enables you to use Oracle Managed
Files (OMF), which enable Oracle to manage the creation and
deletion of data files.
The db_create_file_dest and db_create_online_log_dest_n
parameter specifies the locaton for OMF data files.
OMF limits the file size to 100MB.
OMF files cant be used on raw devices.
All OMF files for data files have to be created in one directory.
Oracle itself recommends OMF files for small and test
databases.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
38
Views for Managing Tablespaces
DBA_DATA_FILES
DBA_TABLESPACES
DBA_FREE_SPACE
DBA_SEGMENTS
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
39
Obtaining Data File and Tablespace
Information from the Control File
V$DATAFILE
- TS#
- NAME
- FILE#
- RFILE#
- STATUS
- ENABLED
- BYTES
- CREATE_BYTES
V$TABLESPACE
- TS#
- NAME
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
40
Guidelines
Use multiple tablespaces.
Specify storage parameters for tablespaces.
Assign tablespace quotas to users.
Use locally managed tablespaces
Can have 1023 data files/tablespace
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
41
Creating and Managing Tables
Create table employee
( empno number(5) primary key,
ename varchar2(15) not null )
Tablespace finan_data01 ;
The employee table is created within the tablespace
finan_data01.
The finan_data01 tablespace is locally managed with segment
space management auto, hence the employee table inherits all
the default storage parameters from the finan_data01
tablespace.
The use of the locally managed tablespace frees you from
having to specify a large number of parameters at table
creation time.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
42
Creating and Managing Tables (contd.)
Specifying Explicit Storage Parameters for a Table
Create table employee
( empno number(5) primary key,
ename varchar2(15) not null )
Pctfree 10
Pctused 40
Tablespace users
Storage ( initial 50k next 50k maxextents 10 pctincrease 25 );
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
43
Creating and Managing Tables (contd.)
Altering Tables
Alter table emp storage ( initial 2m next extent 2m, minextent 2
maxextents 40);
Alter table emp move tablespace users;
Adding a Column to a table
Alter table emp add (retired char(1));
Dropping a Column from a table
Alter table emp drop (retired);
Renaming a table Column
Alter table emp rename column retired to non-active;
Renaming a table
Alter table employee rename to emp;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
44
Creating and Managing Tables (contd.)
Removing all the data from a table
To remove al the rows from a table, you need to use the truncate
command.
Truncate is a DDL command, and therefore it cant be undone by
using the rollback command.
Delete is a DML command and hence write all changes to the
rollback segments which takes longer time to execute.
Truncate table test;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
45
Creating and Managing Tables (contd.)
Creating a new table with the CTAS option
Create table employee_new as
select * from employees;
If the table has millions of rows then you can use parallel and
nologging options with CTAS.
The parallel option enables you to do your data loading in
parallel by several processes.
The nologging option instructs Oracle not to bother logging
the changes to the redo log files and rollback segments.
Create table employee_new
as select * from employees
parallel degree 4
nologging;
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
46
Special Oracle Tables
Temporary Tables
Index-Organized Tables
External Tables
Partitioned Tables
Range Partitioning
Hash Partitioning
List Partitioning
Composite Partitioning
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
47
Clusters
Clusters is use to organize the storing of tables that have
common columns and are usually used together in the same
data block.
The goal is to reduce disk I/O and thereby increase access
speed when you join related tables.
Clusters will reduce the performance of the insert statements,
since more blocks are needed to store clustered tables data
since the data of multiple tables needs to be stored in each
block.
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
48
Distribution of Rows Within a Table
Cluster Index-organized
table
Table
Random
Ordering of Rows
Grouped Ordered
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
49
Clusters
Clustered ORD and
ITEM tables
Cluster Key
(ORD_NO)
101 ORD_DT CUST_CD
05-JAN-97 R01
PROD QTY
A4102 20
A5675 19
W0824 10
102 ORD_DT CUST_CD
07-JAN-97 N45
PROD QTY
A2091 11
G7830 20
N9587 26
Unclustered ORD and
ITEM tables
ORD_NO PROD QTY ...
----- ------ ------
101 A4102 20
102 A2091 11
102 G7830 20
102 N9587 26
101 A5675 19
101 W0824 10
ORD_NO ORD_DT CUST_CD
------ ------ ------
101 05-JAN-97 R01
102 07-JAN-97 N45
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
50
Cluster Types
Index cluster Hash cluster
Hash function Hash function
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
51
Creating Index Clusters
Create a cluster.
Create a cluster index.
CREATE CLUSTER scott.ord_clu
(ord_no NUMBER(3))
SIZE 200 TABLESPACE DATA01
STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0);
CREATE CLUSTER scott.ord_clu
(ord_no NUMBER(3))
SIZE 200 TABLESPACE DATA01
STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0);
CREATE INDEX scott.ord_clu_idx
ON CLUSTER scott.ord_clu
TABLESPACE INDX01
STORAGE(INITIAL 1M NEXT 1M PCTINCREASE 0);
CREATE INDEX scott.ord_clu_idx
ON CLUSTER scott.ord_clu
TABLESPACE INDX01
STORAGE(INITIAL 1M NEXT 1M PCTINCREASE 0);
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
52
Creating Index Clusters
Create tables in the cluster.
CREATE TABLE scott.ord
(ord_no NUMBER(3) CONSTRAINT ord_pk PRIMARY KEY,
ord_dt DATE, cust_cd VARCHAR2(3))
CLUSTER scott.ord_clu(ord_no);
CREATE TABLE scott.ord
(ord_no NUMBER(3) CONSTRAINT ord_pk PRIMARY KEY,
ord_dt DATE, cust_cd VARCHAR2(3))
CLUSTER scott.ord_clu(ord_no);
CREATE TABLE scott.item
(ord_no NUMBER(3) CONSTRAINT item_ord_fk
REFERENCES scott.ord,
prod VARCHAR2(5), qty NUMBER(3),
CONSTRAINT item_pk PRIMARY KEY(ord_no,prod))
CLUSTER scott.ord_clu(ord_no);
CREATE TABLE scott.item
(ord_no NUMBER(3) CONSTRAINT item_ord_fk
REFERENCES scott.ord,
prod VARCHAR2(5), qty NUMBER(3),
CONSTRAINT item_pk PRIMARY KEY(ord_no,prod))
CLUSTER scott.ord_clu(ord_no);
Revision no.: PPT/2K403/02
CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
53
Creating Hash Clusters
Create a cluster.