Indexing in Database
Indexing in Database
Chapter : Objectives
Types of Single-level Ordered Indexes
Primary
Indexes
Clustering Indexes
Secondary Indexes
Multilevel Indexes
Dynamic Multilevel Indexes Using B-Trees
and B+-Trees
Indexes on Multiple Keys
2
Includes one index entry for each block in the data file; the
index entry has the key field value for the first record in the
block, which is called the block anchor
Primary
index on the
ordering key
field of the
file shown in
Figure .
Includes one index entry for each distinct value of the field;
the index entry points to the first data block that contains
records with that field value.
A clustering index
on the DEPTNUMBER
ordering nonkey field
of an
EMPLOYEE file.
10
Clustering index
with a separate
block cluster for
each group of
records that share
the same value for
the clustering field.
11
Includes one entry for each record in the data file; hence, it is a
dense index
12
A dense
secondary index
(with block
pointers) on a
nonordering key
field of a file.
13
14
15
Multi-Level Indexes
Because a single-level index is an ordered file, we can create a
primary index to the index itself ; in this case, 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
16
A two-level
primary index
resembling
ISAM (Indexed
Sequential
Access Method)
organization.
17
Multi-Level Indexes
18
FIGURE 4.8
A node in a search tree with pointers to subtrees
below it.
19
FIGURE 4.9
A search tree of order p = 3.
20
a disk block
21
half full
If a deletion causes a node to become less than half full, it must
22
tree
In a B+-tree, all pointers to data records exists at the leaf-level
nodes
A B+-tree can have less levels (or higher capacity of search
23
FIGURE 4.10
B-tree structures. (a) A node in a B-tree with q 1 search
values. (b) A B-tree of order p = 3. The values were
inserted in the order 8, 5, 1, 7, 3, 12, 9, 6.
24
FIGURE 4.11
The nodes of a B+-tree. (a) Internal node of a B+-tree with q 1 search
values. (b) Leaf node of a B+-tree with q 1 search values and q 1 data
pointers.
25
26
Analyze transactions
To understand functionality of the transactions
and to analyze the important ones.
Identify performance criteria, such as:
transactions that run frequently and will have a
significant impact on performance;
transactions that are critical to the business;
times during the day/week when there will be a
high demand made on the database (called the
peak load).
27
Analyze transactions
Use this information to identify the parts of the
28
29
Choose indexes
Determine whether adding indexes
improve the performance of the system.
will
30
Choose indexes
Or could order records in table by specifying a primary
or clustering index.
In this case, choose the column for ordering or
clustering the records as:
31
Choose indexes
If ordering column chosen is key of table, index will be
32
33
34