patternMinor
Using Hashes as Unique ID
Viewed 0 times
uniqueusinghashes
Problem
I am creating a database that will hold a number of transaction records.
I was wondering if it is a good idea or good practice to use a hash function that can be replicated easily for verification as the ID column. i.e. SHA1(UserID + TimeOfTransaction)
I was wondering if it is a good idea or good practice to use a hash function that can be replicated easily for verification as the ID column. i.e. SHA1(UserID + TimeOfTransaction)
Solution
Generally not a good idea, for the following reasons:
- If someone knows
UserIDand times, they may be able to match that back to transactions (depending on how this ID is exposed - if it's exposed externally via an API, someone knowingUserIDcould generate candidateTransactionIDsfrom guessed times)
- High amount of entropy in the key means that your indexes on this key are going to fragment rapidly. If your DB has a page cache, the cache efficiency will drop as your data volume grows (this can be a killer).
- If you can handle the performance concerns, then why not just generate a GUID?
Context
StackExchange Database Administrators Q#144501, answer score: 3
Revisions (0)
No revisions yet.