Chapter - 8 1 97
Chapter - 8 1 97
Chapter - 8 1 97
Jan - 2015 2
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 3
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 4
Disk Storage Devices
Preferred secondary storage device for high
storage capacity and low cost.
Data stored as magnetized areas on
magnetic disk surfaces.
A disk pack contains several magnetic disks
connected to a rotating spindle.
Disks are divided into concentric circular
tracks on each disk surface .
Track capacities vary typically from 4 to 50
Kbytes.
Jan - 2015 5
Disk Storage Devices (cont.)
Jan - 2015 6
Disk Storage Devices (cont.)
Track
Sector
Spindle
Jan - 2015 7
Disk Storage Devices (cont.)
A track is divided into smaller blocks or
sectors.
because a track usually contains a large amount
of information .
A track is divided into blocks.
The block size B is fixed for each system.
Typical block sizes range from B=512 bytes to
B=4096 bytes.
Whole blocks are transferred between disk and
main memory for processing.
Jan - 2015 8
Disk Storage Devices (cont.)
A read-write head moves to the track that contains the
block to be transferred.
Disk rotation moves the block under the read-write head for
reading or writing.
A physical disk block (hardware) address consists of:
a cylinder number (imaginary collection of tracks of same
radius from all recorded surfaces)
the track number or surface number (within the cylinder)
and block number (within track).
Reading or writing a disk block is time consuming
because of the seek time s and rotational delay (latency)
rd.
Double buffering can be used to speed up the transfer of
contiguous disk blocks.
Jan - 2015 9
Disk storage devices (cont.)
Jan - 2015 10
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 11
Records
Fixed and variable length records.
Records contain fields which have values of a
particular type.
E.g., amount, date, time, age.
Fields themselves may be fixed length or
variable length.
Variable length fields can be mixed into one
record:
Separator characters or length fields are needed
so that the record can be “parsed”.
Jan - 2015 12
Records (cont.)
Jan - 2015 13
Blocking
Blocking: refers to storing a number of
records in one block on the disk.
Blocking factor (bfr): refers to the number
of records per block.
There may be empty space in a block if an
integral number of records do not fit in one
block.
Spanned Records: refer to records that
exceed the size of one or more blocks and
hence span a number of blocks.
Jan - 2015 14
Blocking (cont.)
Jan - 2015 15
Files of Records
A file is a sequence of records, where each record is
a collection of data values (or data items).
A file descriptor (or file header) includes information
that describes the file, such as the field names and
their data types, and the addresses of the file blocks
on disk.
Records are stored on disk blocks.
The blocking factor bfr for a file is the (average)
number of file records stored in a disk block.
A file can have fixed-length records or variable-
length records.
Jan - 2015 16
Files of Records (cont.)
File records can be unspanned or spanned:
Unspanned: no record can span two blocks
Spanned: a record can be stored in more than one block
The physical disk blocks that are allocated to hold the
records of a file can be contiguous, linked, or indexed.
In a file of fixed-length records, all records have the
same format. Usually, unspanned blocking is used with
such files.
Files of variable-length records require additional
information to be stored in each record, such as
separator characters and field types.
Usually spanned blocking is used with such files.
Jan - 2015 17
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 18
Operation on Files
Typical file operations include:
OPEN: Reads the file for access, and associates a
pointer that will refer to a current file record at each point
in time.
FIND: Searches for the first file record that satisfies
a certain condition, and makes it the current file record.
FINDNEXT: Searches for the next file record (from the
current record) that satisfies a certain condition, and
makes it the current file record.
READ: Reads the current file record into a program
variable.
INSERT: Inserts a new record into the file, and
makes it the current file record.
Jan - 2015 19
Operation on Files (cont.)
DELETE: Removes the current file record
from the file, usually by marking the record to
indicate that it is no longer valid.
MODIFY: Changes the values of some fields
of the current file record.
CLOSE: Terminates access to the file.
REORGANIZE: Reorganizes the file records. For
example, the records marked deleted are physically
removed from the file or a new organization of the
file records is created.
READ_ORDERED: Read the file blocks in order of
a specific field of the file.
Jan - 2015 20
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 21
Unordered Files
Also called a heap or a pile file.
New records are inserted at the end of the file.
A linear search through the file records is
necessary to search for a record.
This requires reading and searching half the file
blocks on the average, and is hence quite expensive.
Record insertion is quite efficient.
Reading the records in order of a particular field
requires sorting the file records.
Jan - 2015 22
Ordered Files
Also called a sequential file.
File records are kept sorted by the values of an ordering
field.
Insertion is expensive: records must be inserted in the
correct order.
It is common to keep a separate unordered overflow (or
transaction) file for new records to improve insertion efficiency;
this is periodically merged with the main ordered file.
A binary search can be used to search for a record on
its ordering field value.
This requires reading and searching log2 of the file blocks on the
average, an improvement over linear search.
Reading the records in order of the ordering field is quite
efficient.
Jan - 2015 23
Ordered Files
(cont.)
Jan - 2015 24
Average Access Times
Jan - 2015 25
Hashed Files
Hashing for disk files is called External Hashing.
The file blocks are divided into M equal-sized buckets,
numbered bucket0, bucket1, ..., bucketM-1.
Typically, a bucket corresponds to one (or a fixed number of) disk
block.
One of the file fields is designated to be the hash key of
the file.
The record with hash key value K is stored in bucket i,
where i=h(K), and h is the hashing function.
Search is very efficient on the hash key.
Collisions occur when a new record hashes to a bucket
that is already full.
An overflow file is kept for storing such records.
Overflow records that hash to each bucket can be linked together
Jan - 2015 26
Hashed Files (cont.)
Jan - 2015 27
Hashed Files (cont.)
There are numerous methods for collision resolution,
including the following:
Open addressing: Proceeding from the occupied position specified by
the hash address, the program checks the subsequent positions in
order until an unused (empty) position is found.
0 1 2 3 4 5 6
h(K) = K mod 7
1 3 11 6
Insert 8 1 8 3 11 6
Insert 15 1 8 3 11 15 6
Insert 13 13 1 8 3 11 15 6
Jan - 2015 28
Hashed Files (cont.)
There are numerous methods for collision resolution,
including the following:
Chaining:
Various overflow locations are kept: extending the array with a number
of overflow positions.
A pointer field is added to each record location.
A collision is resolved by placing the new record in an unused overflow
location and setting the pointer of the occupied hash address location
to the address of that overflow location.
Multiple hashing:
The program applies a second hash function if the first results in a
collision.
If another collision results, the program uses open addressing or
applies a third hash function and then uses open addressing if
necessary.
Jan - 2015 29
Hashed Files (cont.) - Overflow handling
Jan - 2015 30
Hashed Files (cont.)
To reduce overflow records, a hash file is typically
kept 70-80% full.
The hash function h should distribute the records
uniformly among the buckets; otherwise, search
time will be increased because many overflow
records will exist.
Main disadvantages of static external hashing:
Fixed number of buckets M is a problem if the number of
records in the file grows or shrinks.
Ordered access on the hash key is quite inefficient
(requires sorting the records).
Jan - 2015 31
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 32
Parallelizing Disk Access using RAID
Technology.
Secondary storage technology must take steps to
keep up in performance and reliability with
processor technology.
A major advance in secondary storage technology is
represented by the development of RAID, which
originally stood for Redundant Arrays of
Inexpensive Disks.
The main goal of RAID is to even out the widely
different rates of performance improvement of disks
against those in memory and microprocessors.
Jan - 2015 33
RAID Technology (cont.)
A natural solution is a large array of small independent
disks acting as a single higher-performance logical disk.
A concept called data striping is used, which utilizes
parallelism to improve disk performance.
Data striping distributes data transparently over multiple
disks to make them appear as a single large, fast disk.
Jan - 2015 34
RAID Technology (cont.)
Different raid organizations were defined based on different
combinations of the two factors of granularity of data interleaving
(striping) and pattern used to compute redundant information.
Raid level 0 has no redundant data and hence has the best write
performance.
Raid level 1 uses mirrored disks.
Raid level 2 uses memory-style redundancy by using Hamming codes,
which contain parity bits for distinct overlapping subsets of components.
Level 2 includes both error detection and correction.
Jan - 2015 35
RAID Technology (cont.)
Raid level 3 uses a single parity disk relying on the disk controller to
figure out which disk has failed.
Raid levels 4 and 5 use block-level data striping, with level 5 distributing
data and parity information across all disks.
Jan - 2015 36
RAID Technology (cont.)
Raid level 6 applies the so-called P + Q redundancy scheme using
Reed-Soloman codes to protect against up to two disk failures by using
just two redundant disks.
Jan - 2015 37
Use of RAID Technology (cont.)
Different raid organizations are being used under different
situations:
Raid level 1 (mirrored disks)is the easiest for rebuild of a disk from other
disks
It is used for critical applications like logs.
Raid level 2 uses memory-style redundancy by using Hamming codes,
which contain parity bits for distinct overlapping subsets of components.
Level 2 includes both error detection and correction.
Raid level 3 ( single parity disks relying on the disk controller to figure
out which disk has failed) and level 5 (block-level data striping) are
preferred for large volume storage, with level 3 giving higher transfer
rates.
Most popular uses of the RAID technology currently are: Level 0 (with
striping), Level 1 (with mirroring) and Level 5 with an extra drive for
parity.
Design decisions for RAID include – level of RAID, number of disks,
choice of parity schemes, and grouping of disks for block-level striping.
Jan - 2015 38
Storage Area Networks
The demand for higher storage has risen
considerably in recent times.
Organizations have a need to move from a static
fixed data center oriented operation to a more
flexible and dynamic infrastructure for information
processing.
Thus they are moving to a concept of Storage Area
Networks (SANs).
In a SAN, online storage peripherals are configured as
nodes on a high-speed network and can be attached and
detached from servers in a very flexible manner.
This allows storage systems to be placed at longer
distances from the servers and provide different
performance and connectivity options.
Jan - 2015 39
Storage Area Networks (contd.)
Advantages of SANs are:
Flexible many-to-many connectivity among servers and
storage devices using fiber channel hubs and switches.
Up to 10km separation between a server and a storage
system using appropriate fiber optic cables.
Better isolation capabilities allowing nondisruptive addition
of new peripherals and servers.
SANs face the problem of combining storage
options from multiple vendors and dealing with
evolving standards of storage management software
and hardware.
Jan - 2015 40
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 41
Indexes as Access Paths
A single-level index is an auxiliary file that
makes it more efficient to search for a record in
the data file.
The index is usually specified on one field of the
file (although it could be specified on several
fields)
One form of an index is a file of entries <field
value, pointer to record>, which is ordered by
field value
The index is called an access path on the field.
Jan - 2015 42
Indexes as Access Paths (cont.)
The index file usually occupies considerably less
disk blocks than the data file because its entries
are much smaller.
A binary search on the index yields a pointer to
the file record.
Indexes can also be characterized as dense or
sparse:
A dense index has an index entry for every search key
value (and hence every record) in the data file.
A sparse (or nondense) index, on the other hand, has
index entries for only some of the search values
Jan - 2015 43
Types of Single-level Ordered Indexes
Primary Indexes
Clustering Indexes
Secondary Indexes
Jan - 2015 44
Primary Index
Jan - 2015 45
Primary key field
ID Name DoB Salary Sex
1
2
Index file 3
(<K(i), P(i)> entries)
4
Primary Block
key value pointer 6
1 7
4 8
8 9
12 10
12
13
15
Jan - 2015 46
Primary Index
Dense or Nondense?
Nondense
Jan - 2015 47
EXAMPLE 1 (1/2)
An ordered file with r = 300,000 records
A disk with block size B = 4,096 bytes
File records are of fxed size and are unspanned,
with record length R = 100 bytes
bfr = (B/R) = (4,096/100) = 40 records per
block
b = (r/bfr) = (300,000/40) = 7,500 blocks
A binary search on the data
fle would need approximately log2 b = (log2
7,500) = 13 block accesses
Jan - 2015 48
EXAMPLE 1 (2/2)
Suppose that
The ordering key feld of the fle is V = 9 bytes long
A block pointer is P = 6 bytes long
Construct a primary index
The size of each index entry is Ri = (9 + 6) = 15 bytes
The blocking factor for the index is bfri = (B/Ri) = (4,096/15) = 273
entries per block
The total number of index entries ri is equal to the number of blocks in
the data fle, which is 7,500
The number of index blocks is hence bi = (ri/bfri) = (7,500/273) = 28
blocks
Searching
Binary search on the index fle would need (log2 bi) = (log2 28) = 5
block accesses
A total of 5 + 1 = 6 block accesses
Jan - 2015 49
Clustering Index
Jan - 2015 50
Clustering field
Jan - 2015 51
Dept_No Name DoB Salary Sex
Clustering field
1
1
2
2
Index file
2
(<K(i), P(i)> entries)
2
Clustering Block 2
field value pointer
1
3
2
3
3
4
4
5 4
Jan - 2015 52
Clustering Index
Dense or Nondense?
Nondense
Jan - 2015 53
EXAMPLE 2
r = 300,000 records, B = 4,096 bytes
The file is ordered by the attribute Zipcode and
there are 1,000 zip codes in the file
Ri = 5-byte Zipcode and 6-byte block pointer
bfri = (B/Ri) = (4,096/11) = 372 index entries
per block
ri = 1000 index entries of the clustering index
bi = (ri/bfri) = (1,000/372) = 3 blocks
A binary search on the index file would need
(log2 bi) = (log2 3) = 2 block accesses
Jan - 2015 54
Secondary index
A secondary index provides a secondary means of
accessing a file.
The data file is unordered on indexing field.
Indexing field:
secondary key (unique value)
nonkey (duplicate values)
Jan - 2015 55
Index file Secondary
(<K(i), P(i)> entries) key field
Index field Block 5
value pointer
13
3
8
4
5 6
6 15
8 3
9
9
11
21
13 … 11
15
18 4
21 23
23 18
Dense or Nondense?
Dense
Jan - 2015 57
Secondary index on non-key field
Discussion: Structure of Secondary index on non-
key field?
Option 1: include duplicate index entries with the
same K(i) value - one for each record.
Option 2: keep a list of pointers <P(i, 1), ..., P(i, k)>
in the index entry for K(i).
Option 3:
more commonly used.
one entry for each distinct index field value + an extra
level of indirection to handle the multiple pointers.
Jan - 2015 58
Secondary
Index on
non-key
field:
option 3
Jan - 2015 59
Secondary index on nonkey field
Number of index entries?
Number of records in data file
Number of distinct index field values
Dense or Nondense?
Dense/ nondense
Jan - 2015 60
EXAMPLE 3
r = 300,000, R = 100 bytes, B = 4,096 bytes, b = 7,500
blocks
A non-ordering key feld of the file that is V = 9 bytes long
A linear search on the file would require b/2 = 7,500/2 =
3,750 block accesses on the average
A secondary index
A block pointer is P = 6 bytes long, so each index entry is Ri = (9
+ 6) = 15 bytes
bfri = (B/Ri) = (4,096/15) = 273 index entries per block
bi = (r/bfri) = (300,000/273) = 1,099 blocks
A binary search on this secondary index needs (log2 bi) =
(log21,099) = 11 block accesses
Total block accesses: 11 + 1 = 12
Jan - 2015 61
Summary of Single-level indexes
Ordered file on indexing field?
Primary index
Clustering index
Indexing field is Key?
Primary index
Secondary index
Indexing field is not Key?
Clustering index
Secondary index
Jan - 2015 62
Summary of Single-level indexes
Dense index?
Secondary index
Nondense index?
Primary index
Clustering index
Secondary index
Jan - 2015 63
Summary of Single-level indexes
Jan - 2015 64
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 65
Multi-Level Indexes
Because a single-level index is an ordered file, we
can create a primary index to the index itself.
The original index file is called the first-level index and the
index to the index is called the second-level index.
We can repeat the process, creating a third, fourth,
..., top level until all entries of the top level fit in
one disk block.
A multi-level index can be created for any type of
first-level index (primary, secondary, clustering) as
long as the first-level index consists of more than
one disk block.
Jan - 2015 66
A two-level primary
index resembling
ISAM (Indexed
Sequential Access
Method)
organization.
Jan - 2015 67
EXAMPLE 4
From example 3: bfri = 273 index entries per
block (fo) and b1 = 1,099 blocks
b2 = (b1/fo) = (1,099/273) = 5 blocks
b3 = (b2/fo) = (5/273) = 1 block
Top level of the index: t = 3
Total block accesses: t + 1 = 3 + 1 = 4 block
accesses
Jan - 2015 68
Multi-Level Indexes
Such a multi-level index is a form of search
tree.
However, insertion and deletion of new index
entries is a severe problem because every
level of the index is an ordered file.
Jan - 2015 69
A Node in a Search Tree with
Pointers to Subtrees below It
Jan - 2015 70
A search tree of order p = 3
Jan - 2015 71
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 72
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees
Most multi-level indexes use B-tree or B+-tree data
structures because of the insertion and deletion
problem.
This leaves space in each tree node (disk block) to allow
for new index entries
These data structures are variations of search trees
that allow efficient insertion and deletion of new
search values.
In B-Tree and B+-Tree data structures, each node
corresponds to a disk block.
Each node is kept between half-full and completely
full.
Jan - 2015 73
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees (cont.)
An insertion into a node that is not full is quite
efficient.
If a node is full, the insertion causes a split into
two nodes.
Splitting may propagate to other tree levels.
A deletion is quite efficient if a node does not
become less than half full.
If a deletion causes a node to become less than
half full, it must be merged with neighboring
nodes.
Jan - 2015 74
Difference between B-tree and B+-tree
In a B-Tree, pointers to data records exist at
all levels of the tree.
In a B+-Tree, all pointers to data records exist
at the leaf-level nodes.
A B+-Tree can have less levels (or higher
capacity of search values) than the
corresponding B-tree.
Jan - 2015 75
B-tree Structures
Jan - 2015 76
The Nodes of a +
B -Tree
Jan - 2015 77
Example of insertion in B+-Tree
p = 3 and pleaf = 2
Jan - 2015 78
Example of insertion in B+-Tree (cont.)
Jan - 2015 79
Example of insertion in B+-Tree (cont.)
Jan - 2015 80
Example of insertion in B+-Tree (cont.)
Jan - 2015 81
Example of insertion in B+-Tree (cont.)
Jan - 2015 82
Example of insertion in B+-Tree (cont.)
Jan - 2015 83
Example of insertion in B+-Tree (cont.)
Jan - 2015 84
+
B -Tree: Delete entry
Start at root, find leaf L where entry belongs.
Remove the entry.
If L is at least half-full, done!
If L has fewer entries than it should,
Try to re-distribute, borrowing from sibling (adjacent node with
same parent as L).
If re-distribution fails, merge L and sibling.
If merge occurred, must delete entry (pointing to
L or sibling) from parent of L.
Merge could propagate to root, decreasing
height.
Jan - 2015 85
Example of deletion from B+-Tree
p = 3 and pleaf = 2.
Delete 5
Jan - 2015 86
Example of deletion from B+-Tree (cont.)
p = 3 and pleaf = 2.
Jan - 2015 87
Example of deletion from B+-Tree (cont.)
p = 3 and pleaf = 2.
Delete 9:
Underflow (merge with left, redistribute)
Jan - 2015 88
Example of deletion from B+-Tree (cont.)
p = 3 and pleaf = 2.
Jan - 2015 89
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
2.4 Indexes in Oracle
Jan - 2015 90
Types of Indexes
B-tree indexes: standard index type
Index-organized tables: the data is itself the index.
Reverse key indexes: the bytes of the index key are
reversed. For example, 103 is stored as 301. The
reversal of bytes spreads out inserts into the index
over many blocks.
Descending indexes: This type of index stores data on
a particular column or columns in descending order.
B-tree cluster indexes: is used to index a table cluster
key. Instead of pointing to a row, the key points to the
block that contains rows related to the cluster key.
Jan - 2015 91
Types of Indexes (cont.)
Bitmap and bitmap join indexes: an index entry
uses a bitmap to point to multiple rows. A bitmap
join index is a bitmap index for the join of two or
more tables.
Function-based indexes:
Includes columns that are either transformed by a
function, such as the UPPER function, or included in
an expression.
B-tree or bitmap indexes can be function-based.
Application domain indexes: customized index
specific to an application.
Jan - 2015 92
Creating Indexes
Simple create index syntax:
CREATE [ UNIQUE | BITMAP ] INDEX
[schema.] <index_name>
ON [schema.] <table_name> (column [ ASC |
DESC ] [ , column [ASC | DESC ] ] ...)
[REVERSE];
Jan - 2015 93
Example of creating indexes
CREATE INDEX ord_customer_ix ON ORDERS
(customer_id);
CREATE INDEX emp_name_dpt_ix ON
HR.EMPLOYEES(last_name ASC, department_id
DESC);
CREATE BITMAP INDEX emp_gender_idx
ON EMPLOYEES (Sex);
CREATE BITMAP INDEX emp_bm_idx
ON EMPLOYEES (JOBS.job_title)
FROM EMPLOYEES, JOBS
WHERE EMPLOYEES.job_id = JOBS.job_id;
Jan - 2015 94
Example of creating indexes (cont.)
Function-Based Indexes:
CREATE INDEX emp_fname_uppercase_idx
ON EMPLOYEES ( UPPER(first_name) );
SELECT First_name, Lname
FROM Employee WHERE UPPER(Lname)= “SMITH”;
CREATE INDEX emp_total_sal_idx
ON EMPLOYEES (salary + (salary *
commission_pct));
SELECT First_name, Lname
FROM Employee
WHERE ((Salary*Commission_pct) + Salary )
> 15000;
Jan - 2015 95
Guidelines for creating indexes
Primary and unique keys automatically have
indexes, but you might want to create an index on a
foreign key.
Create an index on any column that the query uses
to join tables.
Create an index on any column from which you
search for particular values on a regular basis.
Create an index on columns that are commonly
used in ORDER BY clauses.
Ensure that the disk and update maintenance
overhead an index introduces will not be too high.
Jan - 2015 96
Jan - 2015 97