0

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

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 个朋友需要很长时间并且函数打印的响应非常慢。

谢谢火花 在这里找到代码链接

4

2 回答 2

1

加盟怎么样?

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;
于 2013-01-29T11:11:45.103 回答
0

您可以使用这样的连接

SELECT
  is_facebook_user,
  fname,
  lname,
  profilenam,
  mem_id,
  gender,
  profile_type,
  photo_thumb,
  photo_b_thumb
FROM members
  left join (select
           distince   mem_id
         from network
         where mem_id = '$userId'
          OR frd_id = '$userId') as e
    on e.mem_id = members.mem_id
于 2013-01-29T11:22:10.707 回答