database 散列和索引有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13470688/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between hashing and indexing?
提问by user1543957
I have studied hashing in DBMS (extensible, linear) and about Indexing in DBMS (sparse, dense, indexes based on secondary key, etc.), but I am unable to understand what the difference is between Hashing and Indexing. Are these two techniques used together or is just either used? I am confused because the purpose of both techniques seem to be to enable us to retrieve the data quickly, so I think either should be sufficient.
我研究了 DBMS 中的散列(可扩展、线性)和 DBMS 中的索引(稀疏、密集、基于辅助键的索引等),但我无法理解散列和索引之间的区别。这两种技术是一起使用还是只是使用?我很困惑,因为这两种技术的目的似乎都是让我们能够快速检索数据,所以我认为两者都应该足够了。
Can anyone clarify the difference?
任何人都可以澄清区别吗?
回答by Heena Hussain
What is indexing?
什么是索引?
Indexing is a way of sorting a number of records on multiple fields. Creating an index on a field in a table creates another data structure which holds the field value, and pointer to the record it relates to. This index structure is then sorted, allowing Binary Searches to be performed on it.
索引是一种对多个字段上的大量记录进行排序的方法。在表中的字段上创建索引会创建另一个数据结构,该结构保存字段值和指向它相关记录的指针。然后对该索引结构进行排序,允许对其执行二分搜索。
What is hashing?
什么是哈希?
Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value.
散列是将字符串转换为通常较短的固定长度值或表示原始字符串的键。散列用于索引和检索数据库中的项目,因为使用较短的散列键查找项目比使用原始值查找项目更快。
I think this may clear your doubt.
我想这可能会消除你的疑虑。
回答by Aki Suihkonen
Hash is sort of an index: it can be used to locate a record based on a key -- but it doesn't preserve any order of records. Based on hash, one can't iterate to the succeeding or preceding element. This is however, what index does (in the context of databases.)
哈希是一种索引:它可用于根据键定位记录——但它不保留任何记录顺序。基于散列,不能迭代到后一个或前一个元素。然而,这就是索引的作用(在数据库的上下文中)。
回答by Vishnu Maru
- Hashing do not guarantee that distinct values will hash to distinct address.
- Collision is there in Hashing.
- Hashing results in Overflow.
- No need to access an index structure to locate data & then read data from DB File.
- There is command to define Indexing but not for Hashing.
- 散列不保证不同的值会散列到不同的地址。
- 哈希中存在冲突。
- 在溢出中散列结果。
- 无需访问索引结构来定位数据,然后从 DB 文件中读取数据。
- 有定义索引的命令,但没有定义哈希的命令。
回答by RAviRaaJA
Hashingis an advanced searching technique, i.e large data is made into small data items and stored in a table. But indexingand binary searching comes under searching in a linear manner.
散列是一种高级搜索技术,即将大数据制成小数据项并存储在表中。但是索引和二进制搜索是以线性方式进行搜索的。
And also indexingis used for making an index(key) to a combination of multiple fields
并且索引还用于为多个字段的组合创建索引(键)
回答by NIMISHAN
Difference Between Indexing and Hashing
索引和散列之间的区别
By Definition
Indexingis a data structure technique to efficiently retrieve records from the database files based on some attributes on which the indexing took place. On the other hand, hashingis an effective technique to calculate the direct location of a data record on the disk without using an index structure. Thus, this is the main difference between indexing and hashing.
按定义
索引是一种数据结构技术,可根据进行索引的某些属性有效地从数据库文件中检索记录。另一方面,散列是一种无需使用索引结构即可计算数据记录在磁盘上的直接位置的有效技术。因此,这是索引和散列之间的主要区别。
By Functionality
Indexing uses data reference that holds the address of the disk block with the value corresponding to the key while hashing uses mathematical functions called hash functions to calculate direct locations of data records on the disk. Hence, this is also a major difference between indexing and hashing.
按功能
索引使用数据引用保存磁盘块的地址,其值对应于键,而散列使用称为散列函数的数学函数来计算磁盘上数据记录的直接位置。因此,这也是索引和散列之间的主要区别。
Another difference between indexingand hashingis that the hashing works well for large databases than indexing.
索引和散列之间的另一个区别是散列比索引更适用于大型数据库。

