我有以下脚本,以前没问题,但是由于我们的用户群现在已经扩展到近一百万成员,所以脚本现在非常缓慢。我想改进它并需要专家帮助来加快速度,可以通过编码更改、创建索引或两者兼而有之。这是代码:
IF @MODE = 'CREATEREQUEST'
BEGIN
IF NOT EXISTS (SELECT * FROM FriendRequest WHERE FromMemberID = @FromMemberID AND ToMemberID = @ToMemberID)
AND NOT EXISTS (SELECT * FROM MemberConnection WHERE MemberID = @FromMemberID AND ConnMemberID = @ToMemberID)
AND NOT EXISTS (SELECT * FROM MemberConnection WHERE MemberID = @ToMemberID AND ConnMemberID = @FromMemberID)
BEGIN
INSERT INTO FriendRequest (
FromMemberID,
ToMemberID,
RequestMsg,
OnHold)
VALUES (
@FromMemberID,
@ToMemberID,
@RequestMsg,
@OnHold)
END
BEGIN
UPDATE Member SET FriendRequestCount = (FriendRequestCount + 1) WHERE MemberID = @ToMemberID
END
END
您能提供的任何帮助将不胜感激。