Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Performance: Persisted comp. cols vs non-pers.c.c.

Author  Topic 

rams82
Starting Member

1 Post

Posted - 2008-07-04 : 04:46:03
We have alot of tables where we have implemented a column 'SearchColumn' which takes all varchar fields in the table and concatinates them. In our application we use this field only this way:

SELECT [field1], [field2], [field3]
FROM MyTable
WHERE [SearchColumn] LIKE '%value%';


Meaning it needs to perform a table scan everytime.

All best practices/ articles sais that persisted computed columns is faster than non-persisted computed columns. However our tests haven't showed any significant differences. Other than persisted takes alot more space on disk.

So when doing a
[ComputedColumn] LIKE '%value%'
where it contains a wildcard both infront and at the end it actually is better to choose non-persisted ?

contrari4n
Starting Member

27 Posts

Posted - 2008-07-04 : 05:55:32
The LIKE operator will not seek on an index for any type of column when used like this.

... LIKE 'value%' can use an index, but LIKE '%value%' cannot.

The fact that it is a computed column is irrelevant.

You basically have 2 options:

1) Redesign the application so that searching is done differently
2) Have a look at full text indexing, which again may require application changes


Richard Fryar
http://www.sql-server-pro.com
SQL Server Articles and Tips
Go to Top of Page
   

- Advertisement -