rise speed for "sp_Forums_GetTopicsByPage"
This is a StoreProcedure in Forums module.
It used to get topics by @PageNumber, @PageSize.
.....
INSERT INTO #TempTopics
(
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
)
SELECT
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
FROM
v_Forums_Topics WHERE ForumID = @ForumID ORDER BY TopicLastPostDate Desc
....
I think if there have many records from views,you select all every page,not very good.So I think if can use "TOP".
Last I found use "SET ROWCOUNT " can do it.
Now ,it looks like this:
.....
-- fill the temp table with all the topics for the
-- specified forum retrieved from the v_Forums_Topics view
DECLARE @TopSize int
SET @TopSize = (@PageNumber* @PageSize)
SET ROWCOUNT @TopSize
INSERT INTO #TempTopics
(
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
)
SELECT
TopicID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
Email,
ShowEmail
FROM
v_Forums_Topics WHERE ForumID = @ForumID ORDER BY TopicLastPostDate Desc
SET ROWCOUNT 0
-- declare two variables to calculate the range of records to extract for the specified page
.....
The same as "sp_Forums_GetRepliesByPage"
I think this can raise your speed.
I am a Chinese,my English not good!
Thank you!
|