When should you use full-text indexing?

前端 未结 4 638
孤独总比滥情好
孤独总比滥情好 2020-12-08 06:18

We have a whole bunch of queries that \"search\" for clients, customers, etc. You can search by first name, email, etc. We\'re using LIKE statements in the following manner:

4条回答
  •  醉话见心
    2020-12-08 06:54

    According to my test scenario:

    • SQL Server 2008
    • 10.000.000 rows each with a string like "wordA wordB wordC..." (varies between 1 and 30 words)
    • selecting count(*) with CONTAINS(column, "wordB")
    • result size several hundred thousands
    • catalog size approx 1.8GB

    Full-text index was in range of 2s whereas like '% wordB %' was in range of 1-2 minutes.

    But this counts only if you don't use any additional selection criteria! E.g. if I used some "like 'prefix%'" on a primary key column additionally, the performance was worse since the operation of going into the full-text index costs more than doing a string search in some fields (as long those are not too much).

    So I would recommend full-text index only in cases where you have to do a "free string search" or use some of the special features of it...

提交回复
热议问题