Open In App

Dynamic Hashing in DBMS

Last Updated : 01 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn about dynamic hashing in DBMS. Hashing in DBMS is used for searching the needed data on the disc. As static hashing is not efficient for large databases, dynamic hashing provides a way to work efficiently with databases that can be scaled.

What is Dynamic Hashing in DBMS?

Dynamic hashing is a technique used to dynamically add and remove data buckets when demanded. Dynamic hashing can be used to solve the problem like bucket overflow which can occur in static hashing. In this method, the data bucket size grows or shrinks as the number of records increases or decreases. This allows easy insertion or deletion into the database and reduces performance issues.

Important Terminologies Related to Dynamic Hashing

  • Hash Function: A mathematical function that uses the primary key to generate the address of the data block.
  • Data Bucket: These are the memory locations that contain actual data records.
  • Hash Index: It is the address of the data block generated by hash function.
  • Bucket Overflow: Bucket overflow occurs when memory address generated by the hash function is already filled by some data records.

How to Search a Key?

  • Calculate the hash address of key.
  • Calculate the number of bits used in the dictionary and denote these bits as i.
  • Take the least significant i bits of hash address. This provides index of dictionary.
  • This index is used to navigate to the dictionary and check for bucket address in which record may be present.

Advantages of Dynamic Hashing

  • In dynamic hashing, performance will not get affected as the amount of data grows in the system. To accommodate the data, size of memory will be increased.
  • Dynamic hashing improve the utilization of the memory.
  • This method is efficient to handle the dynamic database where size of data changes frequently.

Disadvantages of Dynamic Hashing

  • A the amount of data changes, bucket size will also get changed. Bucket address table will keep track of these addresses because data address changes as bucket size increases or decreases. Maintenance of the bucket address table gets difficult when there is significant increase in data.
  • In dynamic hashing, bucket overflow can happen.

How to Insert a New Record in Database Using Dynamic Hashing?

  • Follow the same procedure that we used for searching which to lead to some bucket.
  • If space is present in that bucket, then place record in it.
  • If bucket is full, then split the bucket and redistribute the records.

Example

Consider the following table which contain key into bucket based on their hash address prefix

Key

Hash Address

1

10000

2

10101

3

11000

4

10011

5

11011

6

11001

7

10110

In the above table, the last two bits of 1 and 3 are 00. So, it will go into bucket B0. The last two bits of 2 and 6 are 01. So, it will go into bucket B1. The last bit of 7 is 10. So, it will go into bucket B2. The last two bits of 4 and 5 are 11. So, they will go into B3.

Mapping of Data Records into Buckets

Mapping of Data Records into Buckets

Now, to insert key 11 with hash address 10001 into the above structure follow the steps:-

  • Since, hash address of the bucket is 10001. It will go into bucket B1. But B1 bucket is already filled, so it will get split.
  • Three bits of 11 and 6 are 001. So, they will go into bucket B1. And last three bits of 2 are 101. So, it will go into B4.
  • Keys 1 and 3 are still in bucket B0. The record B is pointed by 000 and 100 entry because last two bits of both the entry are 00.
  • Key 7 is still in bucket B2. The record B2 is pointed by 010 and 110 entry because last two bits of both the entry are 10.
  • Key 4 and 5 are still in bucket B3. The record B3 is pointed by 111 and 011 entry because last two bits of both the entry are 11.
Insert Key 11 in the Data Bucket

Insert Key 11 in the Data Bucket

Frequently Asked Questions on Dynamic Hashing – FAQs

How is dynamic hashing different from static hashing?

In static hashing, the resultant data bucket address will remain same while in dynamic hashing, the data bucket size shrinks or grows while increase or decrease of records.

Which hashing method is used to access the dynamic files?

Extensible hashing approach simultaneously solves the problem of making hash tables that are extendible and of making radix search trees that are balanced. It can be used to access the dynamic files.

What are popular dynamic hashing techniques?

Some popular dynamic hashing techniques are linear hashing, extensible hashing and consistent hashing.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads