我有以下表格.

条目表描述

+-------------+-------------------+------+-----+---------+----------------+
| Field       | Type              | Null | Key | Default | Extra          |
+-------------+-------------------+------+-----+---------+----------------+
| id          | int(11) unsigned  | NO   | PRI | NULL    | auto_increment |
| title       | varchar(255)      | YES  |     | NULL    |                |
| slug        | varchar(255)      | YES  |     | NULL    |                |
| description | text              | YES  |     | NULL    |                |
| user_id     | int(10) unsigned  | NO   |     | NULL    |                |
| unsafe      | enum('0','1')     | NO   |     | NULL    |                |
| copyright   | enum('0','1')     | NO   |     | 0       |                |
| status      | enum('0','1','2') | NO   |     | 0       |                |
| date_add    | datetime          | NO   |     | NULL    |                |
+-------------+-------------------+------+-----+---------+----------------+

标签表描述

+-------------+---------------------+------+-----+---------+----------------+
| Field       | Type                | Null | Key | Default | Extra          |
+-------------+---------------------+------+-----+---------+----------------+
| id          | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| relation_id | int(10) unsigned    | NO   |     | NULL    |                |
| name        | varchar(255)        | NO   |     | NULL    |                |
+-------------+---------------------+------+-----+---------+----------------+

我想在entry.title和tag.name中搜索.如何才能为此查询提供性能.


我继续使用全文.你怎么 ?

解决方法:

首先,你需要确保标题和名称字段都被编入索引(无法看到你发送的信息.我认为tag.relation\_id与entry.id有关.所以你可以搜索如下:

SELECT * FROM entry as e JOIN tags as t on e.id = t.relation_id WHERE e.title LIKE('%YOURSEARCH%') OR t.name LIKE('%YOURSEARCH%')

标签: mysql, search, full-text-search

相关文章推荐

添加新评论,含*的栏目为必填