I’m building a database for what is soon to be my version of a social networking site. Now, I’d like to store friend relations, sort of like facebook does. I should mention that I’m using MySQL for this.
So i’m thinking of doing something like this:
UserFriends
(
UserFriendID SOME_DATA_TYPE NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserID BIGINT(20) UNSIGNED NOT NULL,
FriendID BIGINT(20) UNSIGNED NOT NULL -- This is basically the same as UserID
)Engine=InnoDB;
Now, I’m looking for some type of data type to use for the primary key for this table as I expect that there will be a ton of records and I’d like some type of indexing to speed up any types of look-up that I might do on the records. Such as a friend suggestion feature etc.
I’m open to suggestions. Another option, in my opinion, but much more difficult to manage is to dynamically create a separate table for each user and store their friends in them, however this would be sort of a nightmare to manage code-wise.
use the same pattern
BIGINT(20)avoid a table per user like the plague 🙂