Most efficient way to search in SQL?

前端 未结 7 2001

I have a database with 75,000+ rows with 500+ entries added per day.

Each row has a title and description.

I created an RSS feed which gives you the latest entri

7条回答
  •  梦毁少年i
    2021-02-08 08:43

    A relatively simple solution for this would be incorporating a FULLTEXT index on these two fields and subsequently searching by using this index.

    ALTER TABLE table ADD FULLTEXT(title, description);
    

    Then would you need to perform a search, you'd do the following:

    SELECT id FROM table
    WHERE MATCH (title, description) AGAINST ('keyterm');
    

    Fulltext indexed search is the automatic solution included in most SQL databases. It's much speedier comparing to doing LIKES. This is also optimized for your specific case because you are only interested in natural language search terms.

    As well, fulltext index has some limiting algorithm for detecting relevancy. You can read more about it here

    EDIT

    In the alter statement, I missed the fulltext index name, it should be:

    ALTER TABLE table ADD FULLTEXT ft_index_name(title, description);
    

提交回复
热议问题