Jump to content

friend system table


Jaynesh

Recommended Posts

Yes if you're using innodb which has a clustered index.  If not, it's more of a tossup -- double the data, vs half the data but 2 indexes.  With that said, the cost on the size of the indexes is something you only have to pay on insert. 

Link to comment
Share on other sites

Ok so if I had one entry how would I adjust my query to affect it both ways.

 

Currently my query pulls a list of all the users friends. This is assuming that there is a double entry.

 

If I have a single entry for e.g

 

user_id  friend id

1            2

 

It treats 2 as a friend of 1 but does not treat 1 as a friend of 2.

 

"SELECT * FROM Users, Friends WHERE user_id = $user and Friends.friend_id = Users.id"

Link to comment
Share on other sites

SELECT * FROM Users, Friends WHERE (Friends.user_id = $user AND Users.id = Friends.friend_id) OR (Friends.friend_id = $user AND Users.id = Friend.user_id)

 

You should probably create a load of test data and benchmark both approaches.  Also make sure you explain extended on the queries.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.