indexing

19
Vu Phan SE157B Spring2007 04/15/2007

Upload: perdy

Post on 06-Jan-2016

35 views

Category:

Documents


3 download

DESCRIPTION

Vu Phan SE157B Spring2007 04/15/2007. Indexing. Overview. Basic Concepts Evaluation Factors Ordered Indices Types of Ordered Indices: Dense Index and Order Index Multilevel Indices Index Update: Insertion and Deletion Secondary Indices. Basic Concepts. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Indexing

Vu PhanSE157B

Spring200704/15/2007

Page 2: Indexing

Overview

Basic Concepts Evaluation Factors Ordered Indices Types of Ordered Indices: Dense

Index and Order Index Multilevel Indices Index Update: Insertion and Deletion Secondary Indices

Page 3: Indexing

Basic Concepts

Purpose: to look up and access desired data quickly

How: Compress files into index files An index file consists index records, or index

entries

Two basic kinds of indices: Ordered indices – store search-keys in a sorted

order Hash indices – store search-keys across “buckets”

using a hash function

Search-key Pointer

Page 4: Indexing

Evaluation Factors

Access types

Access time

Insertion time

Deletion time

Space overhead

Page 5: Indexing

Ordered Indices

Data is sorted sequentially based on the search-key value.

Clustering index Also called primary index Its search key defines the sequential

order of data. Nonclustering index

Also called secondary index Its search key specifies an order

different from the sequential order of data.

Page 6: Indexing

Ordered Indices (Cont.)

Sequential file for account records

Page 7: Indexing

Types of Ordered Indices

Dense index – an index record appears for every search-key value in the file.

Page 8: Indexing

Types of Ordered Indices (Cont.) Sparse index – an index record

appears for only some of the search-key values in the file.

Page 9: Indexing

Dense Index vs. Sparse Index

Dense Index Sparse Index

Access Time Less More

Space More memory Less memory

Space Overhead More Less

Page 10: Indexing

Multilevel Indices

One index may be too large for efficient processing.

Solution: using multilevel index Treat the primary index as a sequence file

and create an sparse index on it Outer index: a sparse index of primary index Inter index: the primary index

If the outer index is still large, creating another level of index is necessary.

Page 11: Indexing

Multilevel Indices (Cont.)

Page 12: Indexing

Index Update

Index must be updated whenever a record is either inserted or deleted from the file.

Two types of index update: insertion and deletion

Page 13: Indexing

Index Update – Insertion

Perform a lookup using the search-key value appearing in the record being inserted.

Dense indices: If search-key value does not appear in the

index, insert the new record to an appropriate position

Otherwise, If the index record stores pointers to all records

with the same search-key value, add a pointer to the new record to the index record

If the index record stores a pointer to only the first record with the same search-key value, just place the record being inserted after the other records with the same search-key values

Page 14: Indexing

Index Update – Insertion (Cont.)

Sparse indices: Assume the index stores an entry for

each block of the file If no new block is created, no change

needs to be made to the index If a new block is created, add the first

search-key value in the new block to the index

Page 15: Indexing

Index Update - Deletion

Dense indices: If the deleted record was the only record

with its unique search-key value, delete it Other wise,

If the index record stores pointers to all records with the same search-key value, delete the point to the deleted record from the index record

If the index record stores a pointer to only the first record with the same search-key value, and if the deleted record was the first record, update the index record to point to the next record

Page 16: Indexing

Index Update – Deletion (Cont.)

Sparse indices: If the deleted record was the only record with its

search key, replace the corresponding index record with an index record for the next search-key value (in search-key order). If the next search-key value already has an index

entry, the index record is deleted instead of being replaced

If the record being deleted was one of many records with the same search-key value, and if the index record points to it, update the index record to point to the next record with the same search-key value

Page 17: Indexing

Secondary Indices

Sometimes we want to find records by an order differed from the sequential order of primary index

Solution: create a secondary index which has different index records of each search-key value

Secondary index record points to a bucket that contains pointers to all actual records

Page 18: Indexing

Secondary Indices

Secondary Indices have to be dense

Page 19: Indexing

References

Silberschatz, Korth, & Sudarshan. Database system Concepts

http://codex.cs.yale.edu/avi/db-book/ Dr. Lee’s lecture