Can a hashing algorithm be used to save space in the database?

I recently used git and I really like the concept of how git can avoid duplicating data like this with a sha1 based hashing function. I was wondering if the current databases do something like this, or is it somehow inefficient?

+2


a source to share


2 answers


I came up with a good "hash reuse" technique (it's probably widely used)

I figured out the hashcode of all fields in the string, and then I used that hashcode as the primary key.



When I pasted, I just did "INSERT IGNORE" (to suppress duplicate primary key errors). In any case, I could be sure that what I wanted to insert was present in the database after the insert.

If this is a known concept, I'd love to hear about it!

+1


a source


There is no need for this. Databases already have a good way to avoid data duplication - database normalization.



For example, imagine you have a column that can contain one of five different rows. Instead of storing one of these rows on each row, you should move that row to a separate table. Create a table with two columns, one with row values ​​and the other as the primary key. Now you can use a foreign key on your original table instead of storing the entire row.

+2


a source







All Articles