SQL Server:普通索引与全文索引
varchar 列上的全文索引和常规索引到底有什么区别(以及优点/缺点)? 我什么时候使用哪个索引?
我有大量 varchar 列(地址 - 城市名称、街道名称等),我需要以最高效的方式对其进行搜索,并且我正在尝试找出要使用的索引类型以及原因。
谢谢你!
what exactly is the difference (and advantages/disadvantages) between a fulltext index and a regular index on a varchar column? When would I use which index?
I have a multitude of varchar columns (addresses - city name, street name etc.) which I need to be searchable in the most performant way and I'm trying to figure out which index type to use and why.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这取决于您想要执行的搜索类型。 例如,您不能在此查询中使用普通索引:
它不是sargable。 这是可控制的,但选择性可能不是很好:
您使用全文索引的方式完全不同:
It depends on the kind of search you want to do. For example, you can't use a normal index with this query:
It's not sargable. This is sargable, but the selectivity might not be very good:
You use a full-text index completely differently:
通常,当使用普通索引搜索时,您只能在单个字段中搜索,例如“查找以 A 开头的所有城市”或类似的内容。
全文索引允许您跨多个列进行搜索,例如在街道、城市、省份等中同时搜索。如果您想做类似 Google 式搜索的操作,这可能是一个优势 - 只需输入搜索词即可找到所有内容在任何 varchar 列中的任意位置具有该搜索词的行。
此外,通过常规搜索,您可以做的事情相当有限 - 您可以搜索完全匹配或只是喜欢 - 仅此而已。
使用全文索引,您可以搜索单词形式(ran、run 等),也可以通过指定您自己的同义词库来搜索类似单词。 如果存在问题,您可以根据多种语言进行搜索。 您可以搜索包含两个或多个彼此“接近”的术语的条目。
马克
Usually, when searching with a normal index, you can search only in a single field, e.g. "find all cities that begin with A" or something like that.
Fulltext index allows you to search across multiple columns, e.g. search at once in street, city, province, etc. That might be an advantage if you want to do something like a Google-style search - just punch in a search term and find all rows that have that search term anywhere in any of the varchar columns.
Additionally, with a regular search, you are fairly limited in what you can do - you can search for an exact match or just LIKE - that's about it.
With fulltext index, you can search for word forms (ran, run, etc.) and also for similar words by specifying your own thesaurus. You can search based on several languages if that's an issue. You can search for entries that have two or more terms that are "NEAR" one another.
Marc
来自 MSDN:
From the MSDN: