Good PHP / MYSQL hashing solution for large number of text values
Posted
by Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2010-05-18T02:01:19Z
Indexed on
2010/05/18
3:10 UTC
Read the original article
Hit count: 284
Short descriptio:
Need hashing algorithm solution in php for large number of text values.
Long description.
PRODUCT_OWNER_TABLE
serial_number (auto_inc), product_name, owner_id
OWNER_TABLE
owner_id (auto_inc), owener_name
I need to maintain a database of 200000 unique products and their owners (AND all subsequent changes to ownership). Each product has one owner, but an owner may have MANY different products. Owner names are "Adam Smith", "John Reeves", etc, just text values (quite likely to be unicode as well).
I want to optimize the database design, so what i was thinking was, every week when i run this script, it fetchs the owner of a proudct, then checks against a table i suppose similar to PRODUCT_OWNER_TABLE, fetching the owner_id. It then looks up owner_id in OWNER_TABLE. If it matches, then its the same, so it moves on. The problem is when its different...
To optimize the database, i think i should be checking against the other "owner_name" entries in OWNER_TABLE to see if that value exists there. If it does, then i should use that owner_id. If it doesnt, then i should add another entry.
Note that there is nothing special about the "name". as long as i maintain the correct linkagaes AND make the OWNER_TABLE "read-only, append-new" type table - I should be able create a historical archive of ownership.
I need to do this check for 200000 entries, with i dont know how many unique owner names (~50000?). I think i need a hashing solution - the OWNER_TABLE wont be sorted, so search algos wont be optimal.
programming language is PHP. database is MYSQL.
© Stack Overflow or respective owner