开发者

Sql Server 2008 FullText Optimization

I am playing a little with fulltext indexes in Sql Server 2008. I created the index, catalog and full populate it. My table has almost 400,000 records. My full text index is defined to a varchar(Max) column (lets call it Text for now). I am executing the follow query:

select * from MyTable where contains(Text, 'house').

This query returns almost 20,000 records in 14 seconds. I think thats very slow. But, when i execute this query:

select Count(*) from MyTable where contains(Text, 'house')

It takes only 1 second to show the result.

I've been looking and as far as I can see, the execution plan is the same for both queries. Why is Sql Server taking that much to show the fist query result?

What I have already did:

I bought a SSD and put both mdf and ldf on this disk. But when I execute the first query, i can see that logs and a tmp database are being created at my HDD (not in the SSD). My SSD is开发者_运维知识库 D: and all temp files are being created at C:.

Is this taking so long because sql needs those files to populate the enterprise manager result grid? is there anything i can do to optimize the Database? I really need the queries to run in less than 2 seconds.


Do you really need to display all that text, or do you want to run some more queries on the results and narrow them further? I assume that most of the 14 seconds are used to display the results -- if you don't need to show them or only want to show some subset of these results, execution time should go down.


Is there any reason why you need to return 20,000 records? Could you add paging to the query so you return the result set in chunks of 20, 100, 1000 or something smaller than 20,000? It's going to take time to return a result set that large, no matter how much you optimize.


Your query's extra time is probably from populating the grid in Management Studio.

Keep in mind that when you do a SELECT * you're also including the Text column itself in the grid results. Try selecting only columns other than your Text column and you will probably see the execution time drop closer to that of your SELECT COUNT(*) query. You might want to also include DATALENGTH(Text) in your select list.

There's also an option in Management Studio that controls the maximum characters retrieved into the grid. You can find it under Tools --> Options --> Query Results --> Results to Grid.


I agree with Christian. Your problem is with the rendering of the result. Try output to Text rather than Grid to eliminate some of this overhead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜