How can I optimize/refactor a TSQL “LIKE” clause?

前端 未结 7 704
野的像风
野的像风 2020-12-10 04:50

I have a table with 117000 or so records. I need to perform a search that checks 3 separate fields for a given string pattern.

My where clause is as follows:

相关标签:
7条回答
  • 2020-12-10 05:45

    Whilst I agree with the accepted answer that Full Text Indexing would be the best solution and am by no means advocating the use of leading wildcard searches if they have to be performed then there are potential steps that can be taken to make the performance of them less bad.

    Kalen Delaney in the book "Microsoft SQL Server 2008 Internals" says:

    Collation can make a huge difference when SQL Server has to look at almost all characters in the strings. For instance, look at the following:

    SELECT COUNT(*) FROM tbl WHERE longcol LIKE '%abc%'
    

    This may execute 10 times faster or more with a binary collation than a nonbinary Windows collation. And with varchar data, this executes up to seven or eight times faster with a SQL collation than with a Windows collation.

    0 讨论(0)
提交回复
热议问题