我正在尝试修复我们网站的问题,我担心此刻有点超出我的深度。我们有一个社交网站,用户可以通过朋友部分搜索朋友。
问题是,当您打开该部分时,SELECT查询似乎会搜索站点上的所有用户。我们有超过15,000名用户,因此页面非常慢,通常会超时。
我能够将显示的结果限制为每页15个用户,但查询没有得到很好的优化,显然选择了所有用户。
以下是我们目前的SELECT查询代码:
$sql_sel_friend_req = "SELECT m.*, mp.iMAgeGroup as modelAgeGroup,
c.iMAgeGroup as clientAgeGroup, mo.iModelId, mp.vImage as modelImage,
cc.vImage as clientImage FROM member m
left join model as mo on (mo.iModelId = m.MemberId && m.MemberType = 'Model')
left join model_profile as mp on (mp.iModelId = mo.iModelId)
left join client as c on (c.iClientId = m.MemberId && m.MemberType = 'Client')
left join client_company as cc on (cc.iClientId = c.iClientId) WHERE m.MemberId != " . $_SESSION['sess_Login_Id'] . " && m.MemberStatus = 'Active' &&
m.MemberId not in (SELECT distinct(mf.iFriendMemberId1) from member_friends mf where mf.iFriendMemberId2 = " . $_SESSION['sess_Login_Id'] . " && mf.eFriendMemberType2 = '" . $_SESSION['sess_Login_Type'] . "') &&
m.MemberId not in (SELECT distinct(mf1.iFriendMemberId2) from member_friends mf1 where mf1.iFriendMemberId1 = " . $_SESSION['sess_Login_Id'] . " && mf1.eFriendMemberType1 = '" . $_SESSION['sess_Login_Type'] . "') ";
我尝试过使用Limit和Offset,但这只会导致SQL错误。
如果您有任何想法,请告诉我。
谢谢