user1543957
user1543957

Reputation: 1828

What is the difference between hashing and indexing?

I have studied hashing in DBMS (extensible, linear) and about Indexing in DBMS (sparse, dense, indexes based on secondary key, etc.), but I am unable to understand what the difference is between Hashing and Indexing. Are these two techniques used together or is just either used? I am confused because the purpose of both techniques seem to be to enable us to retrieve the data quickly, so I think either should be sufficient.

Can anyone clarify the difference?

Upvotes: 30

Views: 60874

Answers (5)

RAviRaaJA
RAviRaaJA

Reputation: 1

Hashing is an advanced searching technique, i.e large data is made into small data items and stored in a table. But indexing and binary searching comes under searching in a linear manner.

And also indexing is used for making an index(key) to a combination of multiple fields

Upvotes: 0

NIMISHAN
NIMISHAN

Reputation: 1265

Difference Between Indexing and Hashing

By Definition
Indexing is a data structure technique to efficiently retrieve records from the database files based on some attributes on which the indexing took place. On the other hand, hashing is an effective technique to calculate the direct location of a data record on the disk without using an index structure. Thus, this is the main difference between indexing and hashing.

By Functionality
Indexing uses data reference that holds the address of the disk block with the value corresponding to the key while hashing uses mathematical functions called hash functions to calculate direct locations of data records on the disk. Hence, this is also a major difference between indexing and hashing.

Another difference between indexing and hashing is that the hashing works well for large databases than indexing.

Upvotes: 0

Vishnu Maru
Vishnu Maru

Reputation: 31

  • Hashing do not guarantee that distinct values will hash to distinct address.
  • Collision is there in Hashing.
  • Hashing results in Overflow.
  • No need to access an index structure to locate data & then read data from DB File.
  • There is command to define Indexing but not for Hashing.

Upvotes: 3

Aki Suihkonen
Aki Suihkonen

Reputation: 20027

Hash is sort of an index: it can be used to locate a record based on a key -- but it doesn't preserve any order of records. Based on hash, one can't iterate to the succeeding or preceding element. This is however, what index does (in the context of databases.)

Upvotes: 16

Heena Hussain
Heena Hussain

Reputation: 3681

What is indexing?

Indexing is a way of sorting a number of records on multiple fields. Creating an index on a field in a table creates another data structure which holds the field value, and pointer to the record it relates to. This index structure is then sorted, allowing Binary Searches to be performed on it.

What is hashing?

Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value.

I think this may clear your doubt.

Upvotes: 27

Related Questions