MySQL FULLTEXT Search Across >1 Table

后端 未结 4 1666
醉话见心
醉话见心 2020-12-18 10:18

As a more general case of this question because I think it may be of interest to more people...What\'s the best way to perform a fulltext search on two tables? Assume there

4条回答
  •  隐瞒了意图╮
    2020-12-18 10:43

    Join after the filters (e.g. join the results), don't try to join and then filter.

    The reason is that you lose use of your fulltext index.

    Clarification in response to the comment: I'm using the word join generically here, not as JOIN but as a synonym for merge or combine.

    I'm essentially saying you should use the first (faster) query, or something like it. The reason it's faster is that each of the subqueries is sufficiently uncluttered that the db can use that table's full text index to do the select very quickly. Joining the two (presumably much smaller) result sets (with UNION) is also fast. This means the whole thing is fast.

    The slow version winds up walking through lots of data testing it to see if it's what you want, rather than quickly winnowing the data down and only searching through rows you are likely to actually want.

提交回复
热议问题