Performance of like '%Query%' vs full text

2019-01-08 12:36发布

I have a situation where I would like to search a single word.

For that scenario, which query would be good from a performance point of view?

Select Col1, Col2 from Table Where Col1 Like '%Search%'

or

Select Col1, Col2 from Table Where Col1 CONTAINS(Col1,'Search')

?

3条回答
我想做一个坏孩纸
2楼-- · 2019-01-08 12:52

For a typical database, the CONTAINS search can be much faster assuming the appropriate full text search index is built on the field being searched. The evaluation of the LIKE operator generally doesn't use an index and thus must read all the data.

查看更多
家丑人穷心不美
3楼-- · 2019-01-08 12:55

Full Text Searching (using the CONTAINS) will be faster/more efficient than using LIKE with wildcarding. Full Text Searching (FTS) includes the ability to define Full Text Indexes, which FTS can use. Dunno why you wouldn't define a FTS index if you intended to use the functionality...

LIKE with wildcarding on the left side (IE: LIKE '%Search') can not use an index (assuming one exists for the column), guaranteeing a table scan. I haven't tested & compared, but regex has the same pitfall. To clarify, LIKE '%Search' and LIKE '%Search%' can not use an index; LIKE 'Search%' can use an index.

查看更多
祖国的老花朵
4楼-- · 2019-01-08 12:55

Like search on Table it self, will kill the performance. Better to apply like search on CTE.

查看更多
登录 后发表回答