Week 7- Indexing Structures (1)
Week 7- Indexing Structures (1)
Outline
• Types of Single-level Ordered Indexes
• Primary Indexes
• Clustering Indexes
• Secondary Indexes
• Multilevel Indexes
• Dynamic Multilevel Indexes Using B-Trees and B+-Trees
Chapter 14-3
• 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
Chapter 14-5
Then, we get:
blocking factor Bfr= B div R= 512 div 150= 3 records/block
number of file blocks b= (r/Bfr)= (30000/3)= 10000 blocks
For an index on the SSN field, assume the field size V SSN=9 bytes,
assume the record pointer size PR=7 bytes. Then:
index entry size RI=(VSSN+ PR)=(9+7)=16 bytes
index blocking factor BfrI= B div RI= 512 div 16= 32 entries/block
number of index blocks b= (r/ BfrI)= (30000/32)= 938 blocks
binary search needs log2bI= log2938= 10 block accesses
• Primary Index
• 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
• A similar scheme can use the last record in a block.
FIGURE 14.1
Primary index
on the
ordering key
field of the file
shown in
Figure 13.7.
Chapter 14-8
• Clustering Index
FIGURE 14.3
Clustering index with a
separate block cluster
for each group of
records that share the
same value for the
clustering field.
Chapter 14-11
FIGURE 14.4
A dense
secondary index
(with block
pointers) on a
nonordering key
field of a file.
Chapter 14-13
FIGURE 14.5
A secondary index (with recored pointers) on a nonkey field implemented using
one level of indirection so that index entries are of fixed length and have unique
field values.
Chapter 14-14
Chapter 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
• 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
Chapter 14-16
FIGURE 14.6
A two-level
primary index
resembling
ISAM (Indexed
Sequential
Access Method)
organization.
Chapter 14-17
Multi-Level Indexes
FIGURE 14.9
A search tree of order p = 3.
Chapter 14-19
FIGURE 14.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.
Chapter 14-23
FIGURE 14.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.
Chapter 14-24
FIGURE 14.12
An example of insertion
in a B+-tree with q = 3
and pleaf = 2.
Chapter 14-25
FIGURE 14.13
An example of
deletion from a
B+-tree.