Download Indexing Structures for Files - Database System - Lecture Slides | CS 6400 and more Study notes Computer Science in PDF only on Docsity!
Chapter 14
Indexing Structures for Files
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Chapter Outline
zTypes of Single-level Ordered Indexes
- Primary Indexes
- Clustering Indexes
- Secondary Indexes
zMultilevel Indexes
zDynamic Multilevel Indexes Using B-Trees
and B+-Trees
zIndexes on Multiple Keys
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
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.
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Types of Single-Level Indexes
z Primary Index
- Defined on an ordered data file
- The data file is ordered on a key field
- 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.
- A primary index is a nondense (sparse) index, since it includes an entry for each disk block of the data file and the keys of its anchor record rather than for every search value.
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
Primary index on the ordering key field of the file shown in Figure 13.7.
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Types of Single-Level Indexes
z Clustering Index
- Defined on an ordered data file
- The data file is ordered on a non-key field unlike primary index, which requires that the ordering field of the data file have a distinct value for each record.
- 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.
- It is another example of nondense index where Insertion and Deletion is relatively straightforward with a clustering index.
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
A clustering index on the DEPTNUMBER ordering nonkey field of an EMPLOYEE file.
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
A dense secondary index (with block pointers) on a nonordering key field of a file.
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
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- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Multi-Level Indexes
z 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.
z We can repeat the process, creating a third, fourth, ...,
top level until all entries of the top level fit in one disk
block
z 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- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
A node in a search tree with pointers to subtrees below it.
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
A search tree of order p = 3.
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Dynamic Multilevel Indexes Using B-Trees
and B+-Trees
z Because of the insertion and deletion problem, most
multi-level indexes use B-tree or B+-tree data
structures, which leave space in each tree node (disk
block) to allow for new index entries
z These data structures are variations of search trees that
allow efficient insertion and deletion of new search
values.
z In B-Tree and B+-Tree data structures, each node
corresponds to a disk block
z Each node is kept between half-full and completely full
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Dynamic Multilevel Indexes Using B-Trees
and B+-Trees (contd.)
z 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
z Splitting may propagate to other tree levels
z A deletion is quite efficient if a node does not become
less than half full
z If a deletion causes a node to become less than half
full, it must be merged with neighboring nodes
Chapter 14- Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
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- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
An example of insertion in a B+-tree with q = 3 and pleaf = 2.
Chapter 14- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
FIGURE 14.
An example of deletion from a B+-tree.