PL-SQL
Oracle PL/SQL FOR LOOP with Example
What is For Loop? "FOR LOOP" statement is best suitable when you want to execute a code for a...
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 is stored in the form of data blocks whose address is generated by applying a hash function in the memory location where these records are stored known as a data block or data bucket.
In this DBMS tutorial, you will learn,
Here, are the situations in the DBMS where you need to apply the Hashing method:
Here, are important terminologies which are used in Hashing:
There are mainly two types of SQL hashing methods:
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 hashing is further divided into
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.
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 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.
| Parameters | Order Indexing | Hashing |
| Storing of address | Addresses in the memory are sorted according to a key value called the primary key | Addresses are always generated using a hash function on the key value. |
| Performance | It can decrease when the data increases in the hash file. As it stores the data in a sorted form when there is any (insert/delete/update) operation performed which decreases its performance. | Performance of hashing will be best when there is a constant addition and deletion of data. However, when the database is huge, then hash file organization and its maintenance will be costlier. |
| Use for | Preferred for range retrieval of data- which means whenever there is retrieval data for a particular range, this method is an ideal option. | This is an ideal method when you want to retrieve a particular record based on the search key. However, it will only perform well when the hash function is on the search key. |
| Memory management | There will be many unused data blocks because of the delete/update operation. These data blocks can't be released for re-use. That's why regular maintenance of the memory is required. | In static and dynamic hashing methods, memory is always managed. Bucket overflow is also handled perfectly to extend static hashing. |
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.
There are two technique which you can use to avoid a hash collision:
What is For Loop? "FOR LOOP" statement is best suitable when you want to execute a code for a...
Download PDF 1) Explain what is SQLite? SQLite is a mostly ACID compliant relational database...
$20.20 $9.99 for today 4.5 (125 ratings) Key Highlights of SQL Tutorial PDF 220+ pages eBook...
SQL Tutorial Summary Databases can be found in almost all software applications. SQL is the...
What are Loops? Loops allows a certain part of the code in a program to get executed for the...
In this tutorial, we are going to learn how to use SQL in PL/SQL. SQL is the actual component that...