Outline ■Basic Concepts ■Ordered Indices B+-Tree Index Files ■B-Tree Index Files ■Hashing Write-optimized indices Spatio-Temporal Indexing Database System Concepts-7th Edition 14.2 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 14.2 ©Silberschatz, Korth and Sudarshan th Edition Outline ▪ Basic Concepts ▪ Ordered Indices ▪ B+ -Tree Index Files ▪ B-Tree Index Files ▪ Hashing ▪ Write-optimized indices ▪ Spatio-Temporal Indexing
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 indexentries)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-7th Edition 14.3 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 14.3 ©Silberschatz, Korth and Sudarshan th Edition 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 ▪ 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”. search-key pointer
Index Evaluation Metrics Access types supported efficiently.E.g., Records with a specified value in the attribute Records with an attribute value falling in a specified range of values. Access time ■Insertion time Deletion time ■Space overhead Database System Concepts-7th Edition 14.4 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 14.4 ©Silberschatz, Korth and Sudarshan th Edition Index Evaluation Metrics ▪ Access types supported efficiently. E.g., • Records with a specified value in the attribute • Records with an attribute value falling in a specified range of values. ▪ Access time ▪ Insertion time ▪ Deletion time ▪ Space overhead
Ordered Indices In an ordered index,index entries are stored sorted on the search key value. Clustering index:in a sequentially ordered file,the index whose search key specifies the sequential order of the file. Also called primary 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 nonclustering index. ■ Index-sequential file:sequential file ordered on a search key,with a clustering index on the search key. Database System Concepts-7th Edition 14.5 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 14.5 ©Silberschatz, Korth and Sudarshan th Edition Ordered Indices ▪ In an ordered index, index entries are stored sorted on the search key value. ▪ Clustering index: in a sequentially ordered file, the index whose search key specifies the sequential order of the file. • Also called primary 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 nonclustering index. ▪ Index-sequential file: sequential file ordered on a search key, with a clustering index on the search key
Dense Index Files Dense index-Index record appears for every search-key value in the file. E.g.index on ID attribute of instructorrelation 10101 10101 Srinivasan Comp.Sci. 65000 12121 12121 Wu Finance 90000 15151 15151 Mozart Music 40000 22222 22222 Einstein Physics 95000 32343 32343 El Said History 60000 33456 33456 Gold Physics 87000 45565 45565 Katz Comp.Sci. 75000 58583 58583 Califieri History 62000 76543 76543 Singh Finance 80000 76766 76766 Crick Biology 72000 83821 83821 Brandt Comp.Sci. 92000 98345 98345 Kim Elec.Eng. 80000 Database System Concepts-7th Edition 14.6 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 14.6 ©Silberschatz, Korth and Sudarshan th Edition 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
Dense Index Files(Cont.) Dense index on dept name,with instructorfile sorted on dept name Biology 76766 Crick Biology 72000 Comp.Sci. 10101 Srinivasan Comp.Sci. 65000 Elec.Eng. 45565 Katz Comp.Sci. 75000 Finance 83821 Brandt Comp.Sci. 92000 History 98345 Kim Elec.Eng. 80000 Music 12121 Wu Finance 90000 Physics 76543 Singh Finance 80000 32343 El Said History 60000 58583 Califieri History 62000 15151 Mozart Music 40000 22222 Einstein Physics 95000 33465 Gold Physics 87000 Database System Concepts-7th Edition 14.7 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 14.7 ©Silberschatz, Korth and Sudarshan th Edition Dense Index Files (Cont.) ▪ Dense index on dept_name, with instructor file sorted on dept_name
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 10101 10101 Srinivasan Comp.Sci. 65000 32343 12121 Wu Finance 90000 76766 15151 Mozart Music 40000 22222 Einstein Physics 95000 32343 El Said History 60000 33456 Gold Physics 87000 45565 Katz Comp.Sci. 75000 58583 Califieri History 62000 76543 Singh Finance 80000 76766 Crick Biology 72000 83821 Brandt Comp.Sci. 92000 98345 Kim Elec.Eng. 80000 Database System Concepts-7th Edition 14.8 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 7 14.8 ©Silberschatz, Korth and Sudarshan th Edition 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
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: for clustered index:sparse index with an index entry for every block in file, corresponding to least search-key value in the block. data block 0 data block 1 For unclustered index:sparse index on top of dense index(multilevel index) Database System Concepts-7th Edition 14.9 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 14.9 ©Silberschatz, Korth and Sudarshan th Edition 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: • for clustered index: sparse index with an index entry for every block in file, corresponding to least search-key value in the block. • For unclustered index: sparse index on top of dense index (multilevel index)
Secondary Indices Example Secondary index on salary field of instructor 40000 10101 Srinivasan Comp.Sci. 65000 60000 12121 Wu Finance 90000 62000 15151 Mozart Music 40000 65000 22222 Einstein Physics 95000 72000 32343 El Said History 60000 75000 33456 Gold Physics 87000 80000 87000 45565 Katz Comp.Sci. 75000 90000 58583 Califieri History 62000 92000 76543 Singh Finance 80000 95000 76766 Crick Biology 72000 83821 Brandt Comp.Sci. 92000 98345 Kim Elec.Eng. 80000 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-7th Edition 14.10 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 14.10 ©Silberschatz, Korth and Sudarshan th Edition 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
Multilevel Index If index does not fit in memory,access becomes expensive. Solution:treat index kept on disk as a sequential file and construct a sparse index on it. outer index-a sparse index of the basic index inner index-the basic 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-7th Edition 14.12 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 14.12 ©Silberschatz, Korth and Sudarshan th Edition Multilevel Index ▪ If index does not fit in memory, access becomes expensive. ▪ Solution: treat index kept on disk as a sequential file and construct a sparse index on it. • outer index – a sparse index of the basic index • inner index – the basic 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