这是我所附的代码,我已经定义了查询。

SELECT
  is_facebook_user,
  fname,
  lname,
  profilenam,
  mem_id,
  gender,
  profile_type,
  photo_thumb,
  photo_b_thumb
FROM members
WHERE mem_id IN(SELECT DISTINCT
          mem_id            AS frnd
        FROM network
        WHERE mem_id = '$userId'
             OR frd_id = '$userId')
ORDER BY profilenam;


在这里我想尽快获取朋友。我还在mem_id和frd_id上应用了索引。但是仍然有2500个朋友花费很长时间并且函数打印响应非常慢。

谢谢
火花
find code link here

最佳答案

加入怎么样?

SELECT
  m.is_facebook_user,
  m.fname,
  m.lname,
  m.profilenam,
  m.mem_id,
  m.gender,
  m.profile_type,
  m.photo_thumb,
  m.photo_b_thumb
FROM members m
  join network n
    on m.mem_id = n.mem_id
WHERE n.mem_id = '$userId'
     or n.frd_id = '$userId'
ORDER BY m.profilenam;

10-07 16:01