我遇到了SQL Server的全文搜索运行速度太慢的问题。
花了一分钟时间来运行全文搜索和JOIN查询(见下文)
select * from
(SELECT
(row_number() over ( order by b.BookKey)) as RowNumber,
p.PublishCity,
b.BookKey,
b.BookTitle
from
Books b (nolock)
inner join PublishedRegions p (nolock)
on b.BookKey = p.BookKey
where
contains(p.PublishCity, 'France') or
contains(b.BookTitle, 'France')
) as t1
where
RowNumber between 200 and 210
任何想法如何提高这个性能?
谢谢!
答案 0 :(得分:2)
如果您使用的是Sql Server 2012+
,那么paging
而不是Row_Number
使用OFFSET..FETCH
。这样的事情。
SELECT
p.PublishCity,
b.BookKey,
b.BookTitle
FROM
Books b (nolock)
INNER JOIN PublishedRegions p (nolock)
ON b.BookKey = p.BookKey
WHERE
CONTAINS(p.PublishCity, 'France') OR
CONTAINS(b.BookTitle, 'France')
ORDER BY b.BookKey OFFSET 199 ROWS FETCH NEXT 11 ROWS ONLY
Offset-Fetch
方法的效果优于Row_number
。 Check here进行详细比较