The difference between hashing and indexing

databasehashindexing

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?

Best Answer

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.