I have two way of doing handling hashed IDs but need your opinions on which one would better over another and why? I'm only interested in the logic rather than what technology I used for hashing or table data type etc!
I'm going to generate an URL to handle deleting a product and the URL will be like this (last segment is hashed (SHA1) product.id):
...../delete/product/123c45c789ds654dedkjfghr87frd
SCENARIO 1: Store hashed ID in table and use it like this:
> Query:
DELETE ...... WHERE hash_id = '$url_hash_id'
> Table:
products
id - INT
hash_id - VARCHAR(40)
SCENARIO 2: Do not store hashed ID in table but generate it everytime when you create the URL and use it like this:
> Query:
DELETE ...... WHERE SHA1(id) = '$url_hash_id'
> Table:
products
id - INT
What I can think of are:
- Scenario 1 - Table gets bigger (potentially whole DB because I might end up implement same column for all the tables) but hashing process is run once.
- Scenario 2 - Less table space used but
mySql SHA1()
function andphp SHA1()
functions are called everytime we need it.