使用row_number时全文索引查询变得很慢?

时间:2018-12-14 10:00:36

标签: sql-server full-text-search row-number sql-optimization

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

0 个答案:

没有答案