mysql - How can I optimize this query to execute faster? -


This is for friends modules on my site, where users can make friends with each other "Friends: "Is stored in the table, whose friendship is friendship as a friendship and the person who gives approval / acceptance to humans is friendly_acceptor

  SELECT user_id, user_name, user_gender Quit user (users) .user_id = friends.friendship_inviter or users.user_id = friends.friendship_accepter) WHERE (f Riendship_inviter = '125' or friendship_accepter = '125') and user_id! = '125' and friendship_level = 1;  

It scans a full table, and although tables are not large (15,000 users, 3000 friendships), it takes 1-1.5 seconds on average.

How can I output the list of existing friends like this which will reduce the server?

  SELECT user_id, user_name, user_gender Leave User WHERE friendship_accepter = '125' and user_id at users.user_id = friends.friendship_accepter = '125' and select friendship_level = 1 union user_id, User_name, leave the user with user_gender friends. Users.user_id = friends.friendship_inviter where friendship repeats = '125' and user_id! = '125' and friendship_level = 1; Of course, it seems that you are not selecting any from the "Friends" table, and you have extra columns in your WHERE section, so I will write INNER JOINS instead. , Which are equivalent to LEFT JOINS in the case you were posted:  
  Include user on user, user_name, user_gender, user on INNER user. User.user_id = friends.friendship_accepter WHERE friendship_accepter = '125' and user_id! = '125' and select friendship_level = 1 union user_id, user_name, user_gender user join user INNER user. User.friendship_inviter Where friendship_inviter = '125' and user_id! = '125' and friendship_level = 1;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -