[问题描述]
因为数据库表中有500万的数据,在做全文检索时,使用分页来显示检索结果。
但发现一个问题,似乎每执行一次全文检索时,好象mssearch都将检索条件带入重新进行一次全文检索。可是我现在比方说只要显示第2页中的数据,那么就要等相当长的时间了。
看一些资料上是说,全文检索时,是先执行mssearch。它负责在全文检索索引文件中找匹配的数据。然后再根据索引中这些数据与表、字段的对应关系由sqlserver来返回结果。[寻求帮助]
有没有什么办法,可以在每次分页处理中,只让mssearch检索出当前页中需要显示的这部分数据,而不要花很长时间去检索出结果,然后由sqlserver来返回其中属于当前页的数据呢。或是有没有其他的好办法可以明显减少时间花费。
谢谢.
因为数据库表中有500万的数据,在做全文检索时,使用分页来显示检索结果。
但发现一个问题,似乎每执行一次全文检索时,好象mssearch都将检索条件带入重新进行一次全文检索。可是我现在比方说只要显示第2页中的数据,那么就要等相当长的时间了。
看一些资料上是说,全文检索时,是先执行mssearch。它负责在全文检索索引文件中找匹配的数据。然后再根据索引中这些数据与表、字段的对应关系由sqlserver来返回结果。[寻求帮助]
有没有什么办法,可以在每次分页处理中,只让mssearch检索出当前页中需要显示的这部分数据,而不要花很长时间去检索出结果,然后由sqlserver来返回其中属于当前页的数据呢。或是有没有其他的好办法可以明显减少时间花费。
谢谢.
然后exec sp_fulltext_service verify_signature,0保证缓存不被清除,保证以后的查询速度
-----------------------------------------
--根据书名搜索图书
create PROCEDURE getBookListSearchByBookName
@keyword nvarchar(500),
@startRow int,--如果每页是20条,第五页的@startRow=100
@stopRow int,--如果每页是20条,第五页的@stopRow=120
@rowCount int output
AS
if @rowCount=0
begin
SELECT @rowCount=count(*)
FROM ContainsTABLE(book,name,@keyword)--根据多次试验,containstable比contains快10倍,当然也就是零点几秒左右
end if @rowCount=0 return declare @t_table table---- 建立有标识符列的table变量
(
[rownum] [int] IDENTITY (1, 1) Primary key NOT NULL,
[id] int,
[isbn] [varchar] (100) ,
[sortId] [smallint] ,
[bookName] [nvarchar](50) ,
[author] [nvarchar](50) ,
[publishingCompanyCode] [varchar](10) ,
[pageCount] [int],
[publishDate] [datetime],
[listPrice] [decimal](10,2),
[summary] [nvarchar](500),
[publishingCompanyName] [nvarchar](20),
[salePrice] [decimal](10,2),
[salePriceVip] [decimal](10,2),
[averageMark] [decimal](4,1),
[storeCounts] [int]
)
SET NOCOUNT ON--关闭统计
Set RowCount @stopRow---- 在返回指定的@stopRow行数之后停止处理查询 insert into @t_table
(
[id],[isbn],[sortId],[bookName],[author],[publishingCompanyCode],[pageCount],
[publishDate],[listPrice],[summary],[publishingCompanyName],[salePrice],[salePriceVip],[averageMark],[storeCounts]
)
select b.id,b.isbn,b.sortId,b.name,b.author,b.publishingCompanyCode,b.pageCount,
b.publishDate,b.listPrice,b.summary,pc.name,
isnull(b.salePrice,0) as salePrice,
isnull(b.salePriceVip,0) as salePriceVip,
isnull(b.averageMark,0) as averageMark,
isnull(b.storeCounts,0) as storeCounts
from book b
inner join publishingCompany pc on b.publishingCompanyCode=pc.code
where CONTAINS(b.name,@keyword)
order by b.sales desc--sales已建非聚集索引 SELECT
[id],[isbn],[sortId],[bookName],[author],[publishingCompanyCode],[pageCount],
[publishDate],[listPrice],[summary],[publishingCompanyName],[salePrice],[salePriceVip],[averageMark],[storeCounts]
FROM @t_table WHERE rownum >= @startRow ORDER BY rownum---- 返回到正确的结果
GO
刚好看到一个。。
地址 http://topic.csdn.net/u/20080320/23/0b8a7e05-26fc-4b12-a996-33a2d262979f.html