Postgresql ILIKE versus TSEARCH

后端 未结 3 889
天涯浪人
天涯浪人 2020-12-17 02:07

I have a query with a number of test fields something like this:

SELECT * FROM some-table
  WHERE field1 ILIKE \"%thing%\"
     OR field2 ILIKE \"%thing\"
           


        
3条回答
  •  抹茶落季
    2020-12-17 02:53

    One thing that is very important: NO B-TREE INDEX will ever improve this kind of search:

    where field ilike '%SOMETHING%'
    

    What I am saying is that if you do a:

    create index idx_name on some_table(field);
    

    The only access you will improve is where field like 'something%'. (when you search for values starting with some literal). So, you will get no benefit by adding a regular index to field column in this case.

    If you need to improve your search response time, definitely consider using FULL TEXT SEARCH.

提交回复
热议问题