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

前端 未结 7 748
野的像风
野的像风 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:26

    Do you really need to start with a wildcard? Why? Often you can force users to type in the first character at least. I bring this up becasue some developers just use the wildcard as a habit not becasue there is a requirement. In most cases users will be able to type the first character unless the filed stores long strings (like say official airport names). Otherwise you really need to use full-text indexing although KM's trick with the reverse is pretty cool if you don't need the wildcard at the end.

    If you can avoid doing the performance killing things, then do so.

提交回复
热议问题