Skip to main content

Hashed files | DBMS - Computer science fundamentals tutorial

 Hashed Files
l Hashing for disk files is called External Hashing

l  The file blocks are divided into M equal-sized buckets, numbered bucket0, bucket1, ...,bucket M-1. Typically, a bucket corresponds to one (or a fixed number of) disk block.

l  One of the file fields is designated to be the hash key of the file.

l  The record with hash key value K is stored in bucket i, where i=h(K), and h is the hashing function.

l  Search is very efficient on the hash key.

l  Collisions occur when a new record hashes to a bucket that is already full. An overflow file is kept for storing such records. Overflow records that hash to each bucket can be linked together.

There are numerous methods for collision resolution, including the following:

l  Open addressing: Proceeding from the occupied position specified by the hash address, the program checks the subsequent positions in order until an unused (empty) position is found.

l  Chaining: For this method, various overflow locations are kept, usually by extending the array with a number of overflow positions. In addition, a pointer field is added to each record location. A collision is resolved by placing the new record in an unused overflow location and setting the pointer of the occupied hash address location to the address of that overflow location.

l  Multiple hashing: The program applies a second hash function if the first results in a collision. If another collision results, the program uses open addressing or applies a third hash function and then uses open addressing if necessary.
Hashed Files

                                                              Figure 1 Hashed Files

l  To reduce overflow records, a hash file is typically kept 70-80% full.

l  The hash function h should distribute the records uniformly among the buckets; otherwise, search time will be increased because many overflow records will exist.

l  Main disadvantages of static external hashing:

         - Fixed number of buckets M is a problem if the number of records in the file grows or shrinks.

         - Ordered access on the hash key is quite inefficient (requires  sorting the records).

Hashed Files - Overflow handling
                                                   Figure 2   Hashed Files - Overflow handling

Dynamic And Extendible Hashed Files

   Dynamic and Extendible Hashing Techniques

l  Hashing techniques are adapted to allow the dynamic growth and shrinking of the number of file records.

l  These techniques include the following: dynamic hashing , extendible hashing , and linear hashing .

l  Both dynamic and extendible hashing use the binary representation  of the hash value h(K) in order to access a directory. In dynamic hashing the directory is a binary tree. In extendible hashing the directory is an array of size 2d where d is called the global depth.

l  The directories can be stored on disk, and they expand or shrink dynamically. Directory entries point to the disk blocks that contain the stored records.

l  An insertion in a disk block that is full causes the block to split into two blocks and the records are redistributed among the two blocks. The directory is updated appropriately.

l  Dynamic and extendible hashing do not require an overflow area.

l  Linear hashing does require an overflow area but does not use a directory. Blocks are split in linear order  as the file expands.

                                                                   Figure 3 
 Extendible Hashing
 Extendible Hashing

Comments

Popular posts from this blog

Solve-write C program to find biggest number from three number by using nested if statement

          C program to find biggest number from three number                                                by using                                                                 nested if statement Problem Description This program takes the 3 numbers and finds the biggest among all. Problem Solution 1. Take the three numbers as input. 2. Check the first number if it greater than other two. 3. Repeat the step 2 for other two numbers. 4. Print the number which is greater among all and exit. Program codes:- here the program of finding biggest of three number run this in your Linux, DEV C++,turbo c++ #include<stdio.h> main() { int num1,num2,num3,big;   ...

Important MCQ of RDBMS( Relational database management system)-FCST

Important MCQ of RDBMS  1. A RDBMS consists a collection of ? a. Tables b. Fields c. Records d. Keys  ANS/- a. table 2. The term attribute refers to a ___________ of a table a. Record b. Tuple c. Column d. Key   ans/- c. Column 3. In relational model, the row of table is known to be ?  a. Relation b. Entity field c. Tuple d. Attribute  ans/- C. Tuple 4. . Address field of a person should not be part of primary key, since it is likely to ? a. Dependent b. Too long c. Changed d. Not changed  ans/- c. Changed 5. The relational model is concerned with ? a. Data structure and Data integrity b. Data Manipulation c. Both a and b d. None of these  ans/- c. Both a and b 6. Which is the false statement from the following ? a. A veiw is a named derived table b. A name relation is variable c. A veiw is a named reation and is virtual d. None of these  ans/- d. None of these 7. The union of primary key...

Short notes on database schema & database independence- computer science fundamentals tutorial

            Database Schema &  Data Independence PDF version of this post also available. to download the click the link given at the end of this post.           Database Schema : -  A database schema   is the skeleton structure that represents the logical view of the entire database. It defines how the data is organized and how relat ion among them are associated.  Database schema  formulates all the constrains that are to be applied on the data. A database schema defines its entities and the relationship among them. It contains descriptive details of the database which can be described by means of schema diagram. A database schema can be divided into two categories.   I.     Physical database schema : - this schema contain to the actual storage of data and its form of storage like files, indices etc. It defines how the data will be stored in a secondary storage. ...