Unit-7 Indexing
Unit-7 Indexing
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
This is compared to an average linear search cost of:
(b/2)= 30000/2= 15000 block accesses
If the file records are ordered, the binary search cost would be:
log2b= log230000= 15 block accesses
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 9 -15
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Types of Single-Level Indexes
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.
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.
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 9 -18
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 9 -19
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 9 -20
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Types of Single-Level Indexes
Secondary Index
– A secondary index provides a secondary means of accessing a
file for which some primary access already exists.
– The secondary index may be on a field which is a candidate key
and has a unique value in every record, or a nonkey with
duplicate values.
– The index is an ordered file with two fields.
The first field is of the same data type as some nonordering
field of the data file that is an indexing field.
The second field is either a block pointer or a record
pointer. There can be many secondary indexes (and hence,
indexing fields) for the same file.
– Includes one entry for each record in the data file; hence, it is a
dense index
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Slide 9 -21
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
A dense secondary index (with
block pointers) on a
nonordering key field of a file.
Hash Indexes
Bitmap Indexes
Function based Indexing