Hashing is a technique used in DBMS to calculate the direct location of a data record on the disk without using an index structure. It is an effective method to index items and retrieve them in a database as it is faster to search for a specific item using the shorter hashed key instead of using its original value. In this technique, data is stored in data blocks whose addresses are generated by using the hashing function. The memory location where these records are stored is known as data bucket or data blocks.
A hash function is a mathematical function that takes a search key as a parameter and generates an address for a data record. The hash function can choose any of the column values to generate the address, but most of the time, it uses the primary key to generate the address of the data block. The primary key itself can be considered as the address of the data block.
There are two types of hashing in DBMS: static hashing and dynamic hashing. In static hashing, the hash function always computes the same address when a search-key value is provided. On the other hand, dynamic hashing provides a mechanism in which data buckets are added and removed dynamically and on-demand. Dynamic hashing is also known as extended hashing.
Hashing is an ideal method to calculate the direct location of a data record on the disk without using an index structure. It is efficient for quick retrieval of data, and it performs well with large data sets, maintaining constant access time. However, hashing is not favorable when the data is organized in some ordering, and the queries require a range of values.