Hashing in DBMS: Static & Dynamic With Examples
Hashing in DBMS: Static & Dynamic With Examples
For a huge database structure, it's tough to search all the index values through all its level
and then you need to reach the destination data block to get the desired data.
Hashing method is used to index and retrieve items in a database as it is faster to search
that specific item using the shorter hashed key instead of using its original value.
Hashing is an ideal method to calculate the direct location of a data record on the disk
without using index structure.
It is also a helpful technique for implementing dictionaries.
1. Static Hashing
2. Dynamic Hashing
Static Hashing
In the static hashing, the resultant data bucket address will always remain the same.
Therefore, if you generate an address for say Student_ID = 10 using hashing function mod(3),
the resultant bucket address will always be 1. So, you will not see any change in the bucket
address.
Therefore, in this static hashing method, the number of data buckets in memory always
remains constant.
/
Static Hash Functions
Inserting a record: When a new record requires to be inserted into the table, you can
generate an address for the new record using its hash key. When the address is generated,
the record is automatically stored in that location.
Searching: When you need to retrieve the record, the same hash function should be helpful
to retrieve the address of the bucket where data should be stored.
Delete a record: Using the hash function, you can first fetch the record which is you wants to
delete. Then you can remove the records for that address in memory.
1. Open hashing
2. Close hashing.
Open Hashing
In Open hashing method, Instead of overwriting older one the next available data block is used
to enter the new record, This method is also known as linear probing.
For example, A2 is a new record which you wants to insert. The hash function generates
address as 222. But it is already occupied by some other value. That's why the system looks for
the next data bucket 501 and assigns A2 to it.
(/images/1/042919_0419_HashinginDB1.png)
How Open Hash Works
Close Hashing /
In the close hashing method, when buckets are full, a new bucket is allocated for the same
hash and result are linked after the previous one.
Dynamic Hashing
Dynamic hashing offers a mechanism in which data buckets are added and removed
dynamically and on demand. In this hashing, the hash function helps you to create a large
number of values.
Storing of Addresses in the memory are sorted Addresses are always generated using
address according to a key value called the a hash function on the key value.
primary key
Performance It can decrease when the data Performance of hashing will be best
increases in the hash file. As it stores when there is a constant addition and
the data in a sorted form when there deletion of data. However, when the
is any (insert/delete/update) database is huge, then hash file
operation performed which organization and its maintenance will
decreases its performance. be costlier.
Use for Preferred for range retrieval of data- This is an ideal method when you
which means whenever there is want to retrieve a particular record
retrieval data for a particular range, based on the search key. However, it
this method is an ideal option. will only perform well when the hash
function is on the search key.
Memory There will be many unused data In static and dynamic hashing
management blocks because of the delete/update methods, memory is always
operation. These data blocks can't managed. Bucket overflow is also
be released for re-use. That's why handled perfectly to extend static
regular maintenance of the memory hashing.
is required.
What is Collision?
Hash collision is a state when the resultant hashes from two or more data in the data set,
wrongly map the same place in the hash table.
1. Rehashing: This method, invokes a secondary hash function, which is applied continuously
until an empty slot is found, where a record should be placed.
2. Chaining: Chaining method builds a Linked list of items whose key hashes to the same
value. This method requires an extra link field to each table position.
Summary:
In DBMS, hashing is a technique to directly search the location of desired data on the disk
without using index structure.
Hashing method is used to index and retrieve items in a database as it is faster to search
that specific item using the shorter hashed key instead of using its original value.
Data bucket, Key , Hash function, Linear Probing, Quadratic probing , Hash index, Double
Hashing, Bucket Overflow are important terminologies used in hashing
Two types of hashing methods are 1) static hashing 2) dynamic hashing
In the static hashing, the resultant data bucket address will always remain the same.
Dynamic hashing offers a mechanism in which data buckets are added and removed
dynamically and on demand.
In order Indexing addresses in the memory are sorted according to a critical value while in
hashing addresses are always generated using a hash function on the key value.
Hash collision is a state when the resultant hashes from two or more data in the data set,
wrongly map the same place in the hash table.
Rehashing and chaining are two methods which help you to avoid hashing collision.
/
DBMS Tutorial
7) DBMS Transaction Management (/dbms-transaction-management.html)
(https://www.facebook.com/guru99com/)
(https://twitter.com/guru99com)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)
(https://forms.aweber.com/form/46/724807646.htm)
About
About Us (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact Us (/contact-us.html)
Career Suggestion
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Interesting
/
Books to Read! (/books.html)
Blog (/blog/)
Quiz (/tests.html)
eBook (/ebook-pdf.html)
Execute online
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html)