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 Wū 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-6th Edition 11.7 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 6 11.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-6th Edition 11.8 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 11.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: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 Database System Concepts-6th Edition 11.9 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 6 11.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: sparse index with an index entry for every block in file, corresponding to least search-key value in the block
Secondary Indices Example 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 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.10 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 6 11.10 ©Silberschatz, Korth and Sudarshan th Edition Secondary Indices Example 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 Secondary index on salary field of instructor
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.11 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 11.11 ©Silberschatz, Korth and Sudarshan th Edition 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