0% found this document useful (0 votes)
162 views8 pages

4.5 Static Hashing, Dynamic Hashing

Uploaded by

Medha Harini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views8 pages

4.5 Static Hashing, Dynamic Hashing

Uploaded by

Medha Harini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

II IV

CS 8492
DATABASE MANAGEMENT SYSTEMS
(Common to CSE & IT)

UNIT NO. 4

4.5 Static Hashing, Dynamic Hashing

Version: 1.0
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

4.5 Static Hashing, Dynamic Hashing


Hashing in DBMS:
Hashing is the technique of the database management system, which directly finds the
specific data location on the disk without using the concept of index structure.
In the database systems, data is stored at the blocks whose data address is produced by
the hash function. That location of memory where hash files stored these records is called a
data bucket or data block.
In this technique, the hash function uses that column, which contains the primary key
constraint for generating the address of the data block.
Hash File organization method is the one where data is stored at the data blocks whose
address is generated by using hash function. The memory location where these records are
stored is called as data block or data bucket. This data bucket is capable of storing one or
more records.
The hash function can use any of the column value to generate the address. Most of
the time, hash function uses primary key to generate the hash index – address of the data
block.
Hash function can be simple mathematical function to any complex mathematical
function. We can even consider primary key itself as address of the data block. That means
each row will be stored at the data block whose address will be same as primary key. This
implies how simple a hash function can be in database.
Static Hashing
In static hashing, the resultant data bucket address will always be the same. That
means if we generate an address for EMP_ID =103 using the hash function mod (5) then it
will always result in the same bucket address 3. Here, there will be no change in the bucket
address.
Hence in this static hashing, the number of data buckets in memory remains constant
throughout. In this example, we will have five data buckets in the memory used to store the
data.
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

Operations of Static Hashing

● Searching a record

When a record needs to be searched, then the same hash function retrieves the address of the
bucket where the data is stored.

● Insert a Record

When a new record is inserted into the table, then we will generate an address for a new
record based on the hash key and record is stored in that location.

● Delete a Record

To delete a record, we will first fetch the record which is supposed to be deleted. Then we
will delete the records for that address in memory.

● Update a Record

To update a record, we will first search it using a hash function, and then the data record is
updated.
If we want to insert some new record into the file but the address of a data bucket
generated by the hash function is not empty, or data already exists in that address. This
situation in the static hashing is known as bucket overflow. This is a critical situation in this
method.To overcome this situation, there are various methods. Some commonly used
methods are as follows:
● Open Hashing
● Close Hashing
1. Open Hashing
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

When a hash function generates an address at which data is already stored, then the next
bucket will be allocated to it. This mechanism is called as Linear Probing.
For example: suppose R3 is a new address which needs to be inserted, the hash function
generates address as 112 for R3. But the generated address is already full. So the system
searches next available data bucket, 113 and assigns R3 to it.

2. Close Hashing

When buckets are full, then a new data bucket is allocated for the same hash result and is
linked after the previous one. This mechanism is known as Overflow chaining.
For example: Suppose R3 is a new address which needs to be inserted into the table, the
hash function generates address as 110 for it. But this bucket is full to store the new data. In
this case, a new bucket is inserted at the end of 110 buckets and is linked to it.

Example of Static Hashing:


CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

In the below image, we can see the records are placed in the A4, B2, C3, and D1 cells
in the Hash table. These records are then passed through the Hash function h(x), in order to
apply the Static Hashing technique.

After the hash function is executed on the records in the table, the records are then
placed in the proper addresses in the storage memory. These new addresses for the given
example are 601, 602, 703, and 804, which are situated to be the outcome of static hashing
process in the DBMS.

Dynamic hashing:

The process of dynamic hashing creates a smaller, adaptable string of characters, making it
faster and easier for users to find objects in a dictionary or groups of objects stored in a
containing data structure.

Dynamic hashing prevents issues caused by a database growing too large and allows for
maximum performance. It addition, it maximizes the available space for objects, tables, and
other data within a system.

Working Procedure:

A hash function is similar to a find and replace feature where programmers are able to
specify a specific item and create a system of rules that change it wherever that item occurs
and the specified criteria are met.
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

In dynamic hashing, only a small amount of data is ever accessed at one time, making it
easier on a computer's resources to perform one or more of the following commands:

● Insert- Adds selected content.


● Delete- Removes selected content.
● Update- Changes selected content.
● Query- Pulls up all results with specified criteria.

Dynamic hashing simplifies the work of searching a large database for a specific piece of
information and performing various actions on it.

How to insert a new record

● Firstly, you have to follow the same procedure for retrieval, ending up in some bucket.
● If there is still space in that bucket, then place the record in it.
● If the bucket is full, then we will split the bucket and redistribute the records.

Example:
Consider the following grouping of keys into buckets, depending on the prefix of their hash
address:

The last two bits of 2 and 4 are 00. So it will go into bucket B0. The last two bits of 5
and 6 are 01, so it will go into bucket B1. The last two bits of 1 and 3 are 10, so it will go
into bucket B2. The last two bits of 7 are 11, so it will go into B3.
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

Insert key 9 with hash address 10001 into the above structure:

● Since key 9 has hash address 10001, it must go into the first bucket. But bucket B1 is
full, so it will get split.
● The splitting will separate 5, 9 from 6 since last three bits of 5, 9 are 001, so it will go
into bucket B1, and the last three bits of 6 are 101, so it will go into bucket B5.
● Keys 2 and 4 are still in B0. The record in B0 pointed by the 000 and 100 entry
because last two bits of both the entry are 00.
● Keys 1 and 3 are still in B2. The record in B2 pointed by the 010 and 110 entry
because last two bits of both the entry are 10.
● Key 7 are still in B3. The record in B3 pointed by the 111 and 011 entry because last
two bits of both the entry are 11.
CS8492

DATABASE MANAGEMENT SYSTEMS


(Common to CSE & IT)

Advantages of dynamic hashing

● In this method, the performance does not decrease as the data grows in the system. It
simply increases the size of memory to accommodate the data.
● In this method, memory is well utilized as it grows and shrinks with the data. There
will not be any unused memory lying.
● This method is good for the dynamic database where data grows and shrinks
frequently.

Disadvantages of dynamic hashing

● In this method, if the data size increases then the bucket size is also increased. These
addresses of data will be maintained in the bucket address table. This is because the
data address will keep changing as buckets grow and shrink. If there is a huge increase
in data, maintaining the bucket address table becomes tedious.
● In this case, the bucket overflow situation will also occur. But it might take little time
to reach this situation than static hashing.

You might also like