table1
的行很大,而field1
是文本,因此我创建了field1
的全文索引。
我在下面运行sql,它运行非常缓慢,并且CPU一直运行到100%。
select * from (
select *, ROW_NUMBER() OVER(Order by [createtime] DESC) AS RowId
from table1
where CONTAINS(field1, 'sometext')
) AS t1
where t1.RowId between 1 and 10
我删除了RowId
查询,查询速度很快,不到1秒。
select * from (
select *, ROW_NUMBER() OVER(Order by [createtime] DESC) AS RowId
from table1
where CONTAINS(field1, 'sometext')
) AS t1
然后我认为这与SQLServer优化有关,我尝试将zero
添加到RowId
查询字段中。
进展很快!但是为什么呢?
select * from (
select *, ROW_NUMBER() OVER(Order by [createtime] DESC) AS RowId
from table1
where CONTAINS(field1, 'sometext')
) AS t1
where t1.RowId + 0 between 1 and 10