Hi everyone
While I've been writing php for a long time, it was always a skill I learnt myself and I've just hit a minor crisis of confidence over table joins!
Assuming a MySQL db auth
containing MyISAM tables users
and permissions
:
users
- id (auto increment)
- email
permissions
- id (auto increment)
- name
To join these tables in a many-to-many (or one-to-many), I've always used bridge tables like so:
user_permissions
- id (auto increment)
- user_id
- permission_id
(I know innoDB is capable of relationships, but it's also more complex and hogs more memory, so for the purpose of the q I'd like to stay with myISAM)
My particular question is this: is it wise to join the tables using the auto-incremented key, or should I be generating my own additional key?
I'm aware that problems could occur if a table gets corrupted and I have to rebuild or if I begin mirroring to two dbs and the keys get out-of-sync.
I'm also aware that if I generate a unique hash for each row (to be used in joins) then there is the overhead of generating a hash and checking that it is new before every data insert.
How does everyone else do it? Are these issues things you have seen in practical situations?
Thanks for your time!
Adam