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
 General SQL Server Forums
 New to SQL Server Programming
 Question about performance of LIKE N'%xxx%'

Author  Topic 

keith_ng
Starting Member

3 Posts

Posted - 2010-08-02 : 00:06:13
I have a Tag table structure is (
id int,
tag nvarchar(400)
)

but it have near 5000000 rows

Now when I use SELECT id FROM tbl WHERE tag LIKE N'%xxx%',
it is very slow, around need 20 sec to get to result.
It's using clustered index scan, but still slowly. have anybody can give me solution or suggestion?

Thank you very much

harrisunderwork
Starting Member

4 Posts

Posted - 2010-08-02 : 00:40:39
I think it depends how many results it return, greater the number, more time it will take.
Go to Top of Page

keith_ng
Starting Member

3 Posts

Posted - 2010-08-02 : 03:51:26
Yes, If I use Select TOP 100 id, it can return below 1 sec.
But I need to get the id to join the product, and I need the total count, so I need to get all records of the condition.
If I use SELECT COUNT(*) also need around 20 sec. do you have any suggestion?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-02 : 04:35:39
MyColumn LIKE 'xxx%'

will be fast if MyColumn is indexed


MyColumn LIKE '%xxx%'

will be slow because it has to check EVERY entry.

Free Text index may be a workaround (if you are looking for words / "language" matches)
Go to Top of Page

keith_ng
Starting Member

3 Posts

Posted - 2010-08-02 : 04:53:06
Free Text index is full-text indexing, right?
I have try to use full-text indexing, the performance is so good. but I have a lot of Chinese, or other language in the field, use full-text indexing always cannot get my expected result...
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-02 : 06:20:39
"Free Text index is full-text indexing, right?"

Yes, that is what I meant
Go to Top of Page
   

- Advertisement -