CSC475 ยท 2081 ยท 5 marks
What is hashing? How does hashing improve database efficiency?
What is hashing? How does hashing improve database efficiency? [5]
Quick answer
Hashing is a technique used to search the location of desired data on disk. It uses a mathematical function called a hash function to calculate the direct location (address) of a data record stored in data blocks (also called data buckets) on disk, without the need for indexing.
Hashing in Database Systems
Definition of Hashing
The hash function can select any column value to generate the address of the data block, but it usually uses the primary key to generate the address.
Formula concept:
Hash Address = hash_function(key value)
How Hashing Improves Database Efficiency
1. Direct Record Access
In large databases, searching through all indexes to find required data is time-consuming. Hashing allows the system to directly compute the disk address of a data record, eliminating the need to scan indexes or perform sequential searches.
2. Faster Data Retrieval
Since the hash function immediately points to the location of the data block, records are retrieved much faster compared to traditional search methods. This directly reduces query execution time.
3. Works Well for Large Databases
Unlike indexing, which does not work well for large databases, hashing works well for large databases because the hash function provides a constant-time lookup regardless of the size of the data.
4. Reduced Disk I/O
By jumping directly to the correct data bucket, hashing minimizes the number of disk read operations, which reduces disk I/O overhead and improves overall system performance.
5. Types of Hashing for Flexibility
Hashing supports two types:
- Static Hashing: Fixed number of buckets; suitable when data size is known.
- Dynamic Hashing: Buckets grow or shrink as data changes; suitable for dynamic datasets.
Comparison: Indexing vs Hashing
| Feature | Indexing | Hashing |
|---|---|---|
| Large Database | Does not work well | Works well |
| Search Method | Data reference / address | Mathematical hash function |
| Access Type | Sequential / tree-based | Direct address computation |
Summary
Hashing improves database efficiency by providing direct, fast, and computed access to data records on disk using a hash function, thereby reducing search time, minimizing disk I/O, and improving overall database performance especially for large-scale systems.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.