1 / 9

Index on EmpID

Index on EmpID. PRIMARY INDEX Key Field (No Repeat Values) Ordering field (records are ordered by the field value). Index on TC ID. SECONDARY – KEY INDEX Key Field (No Repeat Values) Non-Ordering field (records are NOT ordered by the field value). Index on Salary.

aricin
Download Presentation

Index on EmpID

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Index on EmpID • PRIMARY INDEX • Key Field (No Repeat Values) • Ordering field (records are ordered by the field value) Index on TC ID • SECONDARY – KEY INDEX • Key Field (No Repeat Values) • Non-Ordering field (records are NOT ordered by the field value) Index on Salary • SECONDARY – Non- KEY INDEX • Not a Key Field (Repeat Values) • Non-Ordering field (records are NOT ordered by the field value) B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  2. Data File (Records on Disk) Index File (Pointers to records on Disk) • Notes: • Index contains one entry (record) for each block in the data file. • This is because we know that the records are in order. Therefore records with values between 11 and 55 are in the first block, 55 to 99 are in the second etc. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  3. SEARCHING WITH NO INDEX • How many block searches to retrieve the record with the EmpID 180? • What type of search? • Binary search, because the file is ordered by EmpID. • How many searches? On average, for binary search, we need to search log2blocks. Therefore log22500 = 10 block searches to find and retrieve what we are looking for. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  4. Searching using the index: • Search the index file, to find the pointer to the block in the record that contains the correct record. • Retrieve the block in the data file that contains the correct record. • Searching using the index: • Calculate the number of records in each block in the index. • Calculate the number of blocks needed to store the index. • Calculate the number of block searches to search the index. • Add 1 to retrieve the block containing the record in the data file. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  5. Data Required EmpID = 5 bytes Pointer = 7 bytes Size of each index record (Ri) Ri = 5 + 7 = 12 bytes Number of records that fit in a block For the index. bfri = floor(B/Ri) = floor(1024/12) bfri = 85 recs/block Number of blocks needed to store the index Bi = ceiling(ri/bfri) = ceiling(2500/85) = 30 blocks. Therefore, to search the index to find the pointer to the correct block, because it is ordered, we can do a binary search. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  6. bfri = 85 recs/block bi = 30 blocks Therefore, to search the index to find the pointer to the correct block, because it is ordered, we can do a binary search. Binary search takes on average log2block searches. Therefore, to find the pointer in the index file, Log230 = 5 block searches. Then we need to go to the data file and get the block that contains the record. We know exactly which block, because of the pointer, so we only need one more block search. Block searches using the index = 5 + 1 = 6 B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  7. Secondary Key Index TC ID V = 10 bytes P = 7 bytes Index Entries? Index Blocks? B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  8. Secondary Non-Key Index DeptID • Index has one entry for each distinct value of DeptID • Each pointer points to a block of record pointers. • The record pointers point to the records in the data file that contain the id. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

  9. Multi Level Indexes Level 0 Level 1 Level 2 Q: How many levels? A: Top-most level should fıt within a single block. Therefore only 1 block search at each level. B = 1024 b = 2500 bfr = 12 R = 80 r = 30,000

More Related