【发布时间】:2013-03-12 11:47:20
【问题描述】:
假设我有一张电影表:
+------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| title | tinytext | YES | | NULL | |
| synopsis | synopsis | YES | | NULL | |
| year | int(4) | YES | | NULL | |
| ISBN | varchar(13) | YES | | NULL | |
| category | tinytext | YES | | NULL | |
| author | tinytext | YES | | NULL | |
| theme | tinytext | YES | | NULL | |
| edition | int(2) | YES | | NULL | |
| search | text | YES | | NULL | |
+------------+---------------------+------+-----+---------+----------------+
在本例中,我使用search 列作为表的摘要。因此,可能的记录如下:
+------------+-------------------------------------------------------------+
| Field | Value |
+------------+-------------------------------------------------------------+
| id | 1 |
| title | Awesome Book |
| synopsis | This is a cool book with a cool history |
| year | 2013 |
| ISBN | 1234567890123 |
| category | Horror |
| author | John Doe |
| theme | Programmer goes insane |
| edition | 2nd |
| search | 2013 horror john doe awesome book this is a cool book (...) |
+------------+---------------------+------+-----+---------+----------------+
此列search 将在进行搜索时被扫描。请注意,它包含其他字段的所有单词,小写,可能还有一些额外的单词来帮助搜索。
我有两个问题:
1) 知道此列是一个文本字段并且可以变得非常大,是否可以对其进行索引?它会按预期提高性能吗?为什么?
2) 尽管有索引,但使用此方法进行搜索是一个好主意,还是最好尝试查询查询中的每一列?我该如何改进它?
OBS:我并没有这个表,只是为了举例。请忽略我可能所做的数据类型或语法中的任何错误。
【问题讨论】:
-
索引条目在 MySQL 中是有限的(我认为是 8k 之类的),如果插入的值太大而无法索引,您可能会收到错误。为什么不使用全文搜索?
标签: mysql database performance search indexing