This is for the friends module on my site, where users can make friends with each other. These are stored in a "friends:" table, with person who initiated the friendship being the friendship_inviter and the person on the approve/deny end of things is the friendhsip_accepter
SELECT user_id, user_name, user_gender
FROM friends
LEFT JOIN users
ON ( users.user_id = friends.friendship_inviter
OR users.user_id = friends.friendship_accepter)
WHERE (friendship_inviter = '125' OR friendship_accepter = '125')
AND user_id !='125'
AND friendship_level = 1;
This does a full table scan, and even though the tables are not large (15,000 users, 3000 friendships), it takes 1-1.5 seconds on average.
How can I output this list of current friends in a way that would be less taxing n the server?