I have a database table with several columns; most of them are VARCHAR(x)
type columns, and some of these columns have an index on them so that I can search qui
Searching TEXT fields is always pretty slow. Give Full Text Search a try and see if that works better for you.
If your queries are like LIKE '%string%'
(i. e. you search for a string inside a TEXT
field), then you'll need a FULLTEXT
index.
If you search for a substring in the beginning of the field (LIKE 'string%'
) and use SQL Server 2005
or higher, then you can convert your TEXT
into a VARCHAR(MAX)
, create a computed column and index this column.
See this article in my blog for performance details:
You can do complex boolean querying in FTS; like
contains(yourcol,'"My first sting" or "my second string" and "my third string"')
Depending on your query ContainsTable or freetexttable might give better results.
If you are connecting through .Net you might want to look at A google full text search
And since nobody has already said it (maybe because it's obvious) querying LIKE '%string%'
bypasses your existing indexes - so it'll run slow.
Hence - why you need to use full text indexing. (which is what Quassnoi said).
Correction - I'm sure I learnt this, and always believed it - but after some investigating it (using wildcard at the start) seems OK? My old regex queries run better with likes!
You should be looking at using Full Text Indexing on the column.