[Solved] How do I avoid timeouts with SqlServer full text search?

EverSQL Database Performance Knowledge Base

How do I avoid timeouts with SqlServer full text search?

We're using SqlServer 2008. In SSMS, queries on the full text catalog might take 2-5 seconds the first time, but after that, return quite quickly.

On the other hand, running a query from via Linq2Sql will timeout.

Here's what we have:

The SQL Inline Table UDF

CREATE FUNCTION dbo.SearchArchiveFTS
(   
    @query nvarchar(255)
)
RETURNS @ret TABLE 
(
            ID      NVarChar(12) NOT NULL,
            snapshotDate    DateTime NOT NULL,
            -- about 10 more
)
AS BEGIN
    declare @innerQuery nvarchar(255)
    set @innerQuery = @query
    insert into @ret
    select      ID,
                snapshotDate,
                -- about 10 more
        from dbo.Archive a
        where contains(a.*, @innerQuery)
    return

Query in SSMS

select * from dbo.SearchArchiveFTS('query')
//3 seconds / 3k rows

Query in Linq2Sql

db.SearchArchiveFTS("query").ToArray();
// timeout exception

Any ideas on what the problem might be?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Selecting Unnecessary Columns (query line: 2): Avoid selecting all columns with the '*' wildcard, unless you intend to use them all. Selecting redundant columns may result in unnecessary performance degradation.
The optimized query:
SELECT
        * 
    FROM
        dbo.SearchArchiveFTS('query')

Related Articles



* original question posted on StackOverflow here.