SQL Server Full Text Search Optimization

To be honest, there is no elegant way to improve the performance. However, in certain situations you can dramatically improve the performance of a full text query by embedding textual codes within the text column. This will allow you to search both on your embedded textual code and the required search condition. This can reduce the number of rows returned to SQL greatly and change the performance of the full-text query by an order of magnitude.

For example if your data is:

update it to:

PropertyID Type Description
1 HOUSE Big, Nice, Tidy, Shower, Kitchen 
2 FLAT Small, Tidy, Shower, Bath, Gas
3 HOUSE Medium, Average Quality, Bath
……

now you can rewrite your query to the following:

SELECT top 10 *
FROM properties p
INNER JOIN containstable(properties,’”TYPEFLAT” and “bath”‘) t
ON p.PropertyID = t.[key]
WHERE p.type = ‘flat’

For this example, only 2,000 results will be returned to the Query Optimizer, and from this the top 10 rows will be returned to the user. This may be acceptable performance, however, if we run the following query:

SELECT top 10 *
FROM properties p
INNER JOIN containstable(properties,’”TYPEHOUSE” and “bath”‘) 
ON p.PropertyID = t.[key]
WHERE p.type = ‘HOUSE’

In this example, 330,000 rows will be returned to the Query Optimizer, which means performance will still be poor. However, now that we are filtering the results in the Search Service before they are returned to the Query Optimizer, we can specify the number of results we need by using the top_n_by_rank parameter of the containstable function. So rewritten, this query would look like:

SELECT *
FROM properties p
INNER JOIN containstable(properties,’”TYPEFLAT” and “bath”‘,10) t
ON p.PropertyID = t.[key]
WHERE p.type = ‘flat’

Obviously, you don’t want to return the “TYPEFLAT” text in the description column to your database applications, so the final query should look like:

SELECT PropertyID, Type, SubString(description, 9, 9 – LEN(description)) AS description
FROM properties p
INNER JOIN containstable(properties,’”TYPEFLAT” and “bath”‘,10) t
ON p.PropertyID = t.[key]
WHERE p.type = ‘flat’

In this example only 10 rows will be returned the Query Optimizer, so performance should ROCK!  

Obviously you will need to maintain the text code in the full-text column by using triggers, however the overhead in doing so should be minimal when compared to the speed performance gained.




Published with the express written permission of the author. Copyright 2000 Tony Bain.

Pages: 1 2




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |
PropertyID Type Description
1 HOUSE TYPEHOUSE Big, Nice, Tidy, Shower, Kitchen 
2 FLAT TYPEFLAT Small, Tidy, Shower, Bath, Gas
3 HOUSE TYPEHOUSE Medium, Average Quality, Bath
……