gpt4 book ai didi

MySQL/RDBMS : Is it okay to index long strings? 它会完成这项工作吗?

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:37 27 4
gpt4 key购买 nike

假设我有一张电影表:

+------------+---------------------+------+-----+---------+----------------+
| 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:我真的没有这张表,它只是为了举例。请忽略我可能在数据类型或语法中所做的任何错误。

最佳答案

1) Knowing that this column is a text field and can get really big, is it okay to index it? Will it improve the performance as expected? Why?

是的,你可以索引它,但是不行,它不会提高性能。字符串类型列上的索引仅在查询与列的开头匹配时才有帮助 - 因此在您的情况下,搜索“2013 horror john”的人会点击索引,但搜索“horror john 2013”​​的人不会。

2) Despite the index, is it a good idea to use this method to search or is it better to try every column on my query? How can I improve it?

正如 Gordon Linoff 所写,最好的解决方案可能是 full text searching - 这对于文本搜索来说非常快,处理“模糊”匹配,并且通常允许您编写类似于谷歌工作方式的搜索功能。

关于MySQL/RDBMS : Is it okay to index long strings? 它会完成这项工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15573418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com