Download presentation
Presentation is loading. Please wait.
1
Database Management System
Lecture - 36 © Virtual University of Pakistan
2
Direct Access (Hashing)
Provides rapid, non-sequential, direct access to records. © Virtual University of Pakistan
3
© Virtual University of Pakistan
Hashing A key record field is used to calculate the record address by subjecting it to some calculation; a process called hashing. © Virtual University of Pakistan
4
© Virtual University of Pakistan
Hashing For numeric ascending order a sequential key record fields this might involve simply using relative address indexes from a base storage address to access records. © Virtual University of Pakistan
5
© Virtual University of Pakistan
Hashing Most of the time, key field does not have the values in sequence that can directly be used as relative record number Has to be transformed © Virtual University of Pakistan
6
© Virtual University of Pakistan
Hashing Algorithms There are many Two very well known are Prime division/remainder method Folding method © Virtual University of Pakistan
7
© Virtual University of Pakistan
Example Suppose National ID Card number is the key for employees’ record; format is New ID Card Numbers (hope you have them) We take the middle part and transform them into a relative record number © Virtual University of Pakistan
8
© Virtual University of Pakistan
Hashing Example Now the middle part consists of 7 digits can hold numbers up to one million, whereas our organization has maximum of 800 employees © Virtual University of Pakistan
9
© Virtual University of Pakistan
Hashing Example Dividing the middle part with 1000 and using remainder as the hash number 999 © Virtual University of Pakistan
10
© Virtual University of Pakistan
Folding Hash Algo Key value: Hashing method: Folding Split number into 3–digits parts, except the middle one, like © Virtual University of Pakistan
11
© Virtual University of Pakistan
Folding Hashing Algo Add these three components, we get 1150, take three least significant digits, so the key becomes 150 © Virtual University of Pakistan
12
© Virtual University of Pakistan
Hashing Algo Smart Algorithm is the one that generates the key values uniformly COLLISIONS cannot be avoided altogether © Virtual University of Pakistan
13
© Virtual University of Pakistan
Key Collision Like, applying previous algorithm on gives the value 1150 Considering the three least significant numbers the we get 150, which is collision © Virtual University of Pakistan
14
© Virtual University of Pakistan
Collision Handling Records are arranged in buckets; collection of records Keys are generated for buckets Leave spare record places in buckets © Virtual University of Pakistan
15
© Virtual University of Pakistan
Collision Handling If we expect 800 records, and with the 4 records per bucket we need 200 buckets, but rather than generating hash key up to 200, we fix the range as 250, this leaves extra space in each bucket © Virtual University of Pakistan
16
© Virtual University of Pakistan
Collision Handling Find the place for collided record in the next buckets OR leave a separate overflow area for collided records © Virtual University of Pakistan
17
Direct Access (Bucket overflow)
An overflow area is set aside to deal with the bucket overflow problem A synonym pointer at the end of the bucket area points to the first record in its corresponding overflow area. © Virtual University of Pakistan
18
Direct Access (Bucket overflow)
Each record in the overflow area contains a next synonym pointer to a possible next record in that bucket overflow area. © Virtual University of Pakistan
19
Direct Access (Bucket overflow)
Prime Area Bucket 0 | 2500 5300 2200 3400 3800 4500| Bucket 1 | 8901 7901 3201 5701 | … …|| Bucket 2 |3902 4502 2202 Overflow Area | | 5500 © Virtual University of Pakistan
20
Summary of Data Storage Concepts
Different types of storage devices are available for storing data Different file organizations are available to store data. © Virtual University of Pakistan
21
© Virtual University of Pakistan
Indexes and Views © Virtual University of Pakistan
22
© Virtual University of Pakistan
Introduction Sometimes, we want to retrieve records by specifying the values in one or more fields, e.g., Find all students in the “CS” department Find all students with a gpa > 3.0 © Virtual University of Pakistan
23
© Virtual University of Pakistan
Introduction An index on a table is a disk-based data structure (stored as file) that speeds up selections on the search key fields for the index. A schema object © Virtual University of Pakistan
24
Database Management System
Lecture - 36 © Virtual University of Pakistan
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.