0% found this document useful (0 votes)
86 views15 pages

Indexing: Database System Concepts, 6 Ed

Indexing mechanisms are used to speed up access to desired data. There are two basic kinds of indices: ordered indices where search keys are stored in sorted order and hash indices where search keys are distributed using a hash function. Index files contain index entries with a search key and pointer. Secondary indices allow finding records based on a field other than the primary search key.

Uploaded by

Junaid Qureshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views15 pages

Indexing: Database System Concepts, 6 Ed

Indexing mechanisms are used to speed up access to desired data. There are two basic kinds of indices: ordered indices where search keys are stored in sorted order and hash indices where search keys are distributed using a hash function. Index files contain index entries with a search key and pointer. Secondary indices allow finding records based on a field other than the primary search key.

Uploaded by

Junaid Qureshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Indexing

Database System Concepts, 6th Ed.


©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Basic Concepts

 Indexing mechanisms used to speed up access to desired data.


 E.g., author catalog in library
 Search Key - attribute to set of attributes used to look up records in a
file.
 An index file consists of records (called index entries) of the form

search-key pointer
 Index files are typically much smaller than the original file
 Two basic kinds of indices:
 Ordered indices: search keys are stored in sorted order
 Hash indices: search keys are distributed uniformly across
“buckets” using a “hash function”.

Database System Concepts - 6th Edition 11.2 ©Silberschatz, Korth and Sudarshan
Index Evaluation Metrics
 Access types supported efficiently. E.g.,
 records with a specified value in the attribute
 or records with an attribute value falling in a specified range of
values.
 Access time
 Insertion time
 Deletion time
 Space overhead

Database System Concepts - 6th Edition 11.3 ©Silberschatz, Korth and Sudarshan
Ordered Indices

 In an ordered index, index entries are stored sorted on the search key
value. E.g., author catalog in library.
 Primary index: in a sequentially ordered file, the index whose search
key specifies the sequential order of the file.
 Also called clustering index
 The search key of a primary index is usually but not necessarily the
primary key.
 Secondary index: an index whose search key specifies an order
different from the sequential order of the file. Also called
non-clustering index.
 Index-sequential file: ordered sequential file with a primary index.

Database System Concepts - 6th Edition 11.4 ©Silberschatz, Korth and Sudarshan
Dense Index Files
 Dense index — Index record appears for every search-key
value in the file.
 E.g. index on ID attribute of instructor relation

Database System Concepts - 6th Edition 11.5 ©Silberschatz, Korth and Sudarshan
Dense Index Files (Cont.)
 Dense index on dept_name, with instructor file sorted on
dept_name

Database System Concepts - 6th Edition 11.6 ©Silberschatz, Korth and Sudarshan
Sparse Index Files
 Sparse Index: contains index records for only some search-key
values.
 Applicable when records are sequentially ordered on search-key
 To locate a record with search-key value K we:
 Find index record with largest search-key value < K
 Search file sequentially starting at the record to which the index
record points

Database System Concepts - 6th Edition 11.7 ©Silberschatz, Korth and Sudarshan
Sparse Index Files (Cont.)
 Compared to dense indices:
 Less space and less maintenance overhead for insertions and
deletions.
 Generally slower than dense index for locating records.
 Good tradeoff: sparse index with an index entry for every block in file,
corresponding to least search-key value in the block.

Database System Concepts - 6th Edition 11.8 ©Silberschatz, Korth and Sudarshan
Secondary Indices Example

Secondary index on salary field of instructor

 Index record points to a bucket that contains pointers to all the


actual records with that particular search-key value.
 Secondary indices have to be dense

Database System Concepts - 6th Edition 11.9 ©Silberschatz, Korth and Sudarshan
Primary and Secondary Indices
 Indices offer substantial benefits when searching for records.
 BUT: Updating indices imposes overhead on database
modification --when a file is modified, every index on the file
must be updated,
 Sequential scan using primary index is efficient, but a
sequential scan using a secondary index is expensive
 Each record access may fetch a new block from disk
 Block fetch requires about 5 to 10 milliseconds, versus
about 100 nanoseconds for memory access

Database System Concepts - 6th Edition 11.10 ©Silberschatz, Korth and Sudarshan
Multilevel Index
 If primary index does not fit in memory, access becomes
expensive.
 Solution: treat primary index kept on disk as a sequential file
and construct a sparse index on it.
 outer index – a sparse index of primary index
 inner index – the primary index file
 If even outer index is too large to fit in main memory, yet
another level of index can be created, and so on.
 Indices at all levels must be updated on insertion or deletion
from the file.

Database System Concepts - 6th Edition 11.11 ©Silberschatz, Korth and Sudarshan
Multilevel Index (Cont.)

Database System Concepts - 6th Edition 11.12 ©Silberschatz, Korth and Sudarshan
Index Update: Deletion

 If deleted record was the


only record in the file with its
particular search-key value,
the search-key is deleted
from the index also.
 Single-level index entry deletion:
 Dense indices – deletion of search-key is similar to file record
deletion.
 Sparse indices –
 if an entry for the search key exists in the index, it is
deleted by replacing the entry in the index with the next
search-key value in the file (in search-key order).
 If the next search-key value already has an index entry, the
entry is deleted instead of being replaced.
Database System Concepts - 6th Edition 11.13 ©Silberschatz, Korth and Sudarshan
Index Update: Insertion
 Single-level index insertion:
 Perform a lookup using the search-key value appearing in
the record to be inserted.
 Dense indices – if the search-key value does not appear in
the index, insert it.
 Sparse indices – if index stores an entry for each block of
the file, no change needs to be made to the index unless a
new block is created.
 If a new block is created, the first search-key value
appearing in the new block is inserted into the index.
 Multilevel insertion and deletion: algorithms are simple
extensions of the single-level algorithms

Database System Concepts - 6th Edition 11.14 ©Silberschatz, Korth and Sudarshan
Secondary Indices
 Frequently, one wants to find all the records whose values in
a certain field (which is not the search-key of the primary
index) satisfy some condition.
 Example 1: In the instructor relation stored sequentially by
ID, we may want to find all instructors in a particular
department
 Example 2: as above, but where we want to find all
instructors with a specified salary or with salary in a
specified range of values
 We can have a secondary index with an index record for
each search-key value

Database System Concepts - 6th Edition 11.15 ©Silberschatz, Korth and Sudarshan

You might also like