Oracle DBA Basics 2
Oracle DBA Basics 2
1
Srinivasan.K
[email protected]
Agenda
Oracle Index
Table Partitions
2
Oracle Index
What is an index ?
An index is a performance-tuning method of allowing
faster retrieval of records.
An index creates an entry for each value that appears
in the indexed columns.
By default, Oracle creates B-tree indexes.
Types of Index
B-Tree index
Bitmap index
3
Oracle Index
B-Tree index
B(inary)-Tree Indexes are used on HIGH CARDINALITY
columns (i.e. columns which have relatively large number of
distinct values) or on HIGH SELECTIVITY columns (i.e.
columns having the capability to filter-out majority of the rows
when used in a WHERE clause).
Examples of high SELECTIVITY columns are Primary key
columns & columns having relatively less number of duplicate
values.
For instance, if a table has 1, 00,000 records and one of its
indexed columns have 81,000 distinct values, and then the
selectivity of the index is 0.81. Ideal selectivity for an indexed
column is 1 (which is true in the case of primary key indexes).
4
cont'd
Oracle Index
Syntax :
CREATE [UNIQUE] INDEX index_name ON table_name (column1,
column2, . column_n);
For example :
CREATE INDEX supplier_idx ON supplier (supplier_name);
Bitmap Index
A bitmap index is a type of index that uses a string of bits to
quickly locate rows in a table
Bitmap indexes are normally used to index low cardinality columns
in a warehouse environment.
Syntax :
CREATE BITMAP INDEX <index_name> on
<table_name>(<column_name>);
5
cont'd
Table partitions
For example :
CREATE BITMAP INDEX emp_bitmap_idx
ON big_emp(sex);
Table partitions
Partitioning enables tables and indexes to be subdivided
into smaller manageable pieces and these each small
piece is called a "partition".
From an "Application Development" perspective, there
is no difference between a partitioned and a non-
partitioned table.
The application need not be modified to access a
partitioned table if that application was initially written on
a non partitioned tables.
Cont'd 6
Table partitions
cont'd
7
Table partitions
Range partitioning
This type of partitioning is useful when dealing with data that
has logical ranges into which it can be distributed
Range partitions requires scalar numeric values.
Performance is best when the data evenly distributes across
the range.
For example :
CREATE TABLE emp (
empno NUMBER(4),
ename VARCHAR2(30),
sal NUMBER )
PARTITION BY RANGE(empno) (
partition e1 values less than (1000) tablespace ts1,
partition e2 values less than (2000) tablespace ts2,
8
partition e3 values less than (MAXVALUE) tablespace ts3); comt'd
Table partitions
List partitioning
List partitioned is used when you require explicit control
over how rows map to partitions.
Specify a list of discrete values for the partitioning column
in the description for each partition.
List partitioning allows partitioning by non-scalar data.
For example :
CREATE TABLE myemp_work ( empno NUMBER PRIMARY KEY,
ename VARCHAR2(30),
salary NUMBER(8,2),
deptno NUMBER)
PARTITION BY LIST (deptno)
( PARTITION p10 VALUES (10),
PARTITION p20 VALUES (20),
9
PARTITION p30 VALUES (30,40)); cont'd
Table partitions
Hash partitioning
Partitions is based on a hashing algorithm
Evenly distributing data between the partitions.
This is typically used where ranges aren't appropriate, i.e. customer
number, product ID
For example :
CREATE TABLE sales_hash
(salesman_id NUMBER(5),
salesman_name VARCHAR2(30),
sales_amount NUMBER(10),
week_no NUMBER(2))
PARTITION BY HASH(salesman_id)
PARTITIONS 4
STORE IN (data1, data2, data3, data4);
The preceding statement creates a table sales_hash, which is hash partitioned
10
on salesman_id field. The tablespace names are data1, data2, data3, and data4. Cont'd
Oracle Enterprise Manager
Plan
---------------------------------------------
SELECT STATEMENT
TABLE ACCESS FULL PER_ALL_PEOPLE_F
* Every row in the table per_all_people_f is accessed, and the WHERE clause
criteria is evaluated for every row.
* The SELECT statement returns the rows meeting the WHERE clause criteria.
Cont'd 15
Analysing Query plans
Example 2
EXPLAIN PLAN SET statement_id = 'example_plan2' FOR
SELECT full_name FROM per_all_people_f
WHERE full_name LIKE 'Pe%' ;
Plan
---------------------------------------------
SELECT STATEMENT
TABLE ACCESS BY INDEX ROWID PER_ALL_PEOPLE_F
INDEX RANGE SCAN PER_PEOPLE_F_N54
http://www.lorentzcenter.nl/
http://www.techonthenet.com/
Table Partitions
http://www.oracle-dba-online.com/
http://www.oracle-base.com/
http://www.oracle-base.com/
17
Q&A
18
THANKS
19