Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add hash index description #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mysql/index/index_interview.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,15 @@ B+Tree 只在叶子节点存储数据,而 B 树 的非叶子节点也要存储

***3, B+Tree vs Hash***

Hash 在做等值查询的时候效率贼快,搜索复杂度为 O(1)。
Hash 在做等值查询的时候效率贼快,搜索复杂度为 O(1)。但也有其局限性:

但是 Hash 表不适合做范围查询,它更适合做等值的查询,这也是 B+Tree 索引要比 Hash 表索引有着更广泛的适用场景的原因。
- **数据顺序性**:哈希表无法提供数据的顺序访问,更适合做等值的查询。很多查询不仅需要找到特定的键值,还需要根据键值排序来返回结果,或者执行范围查询。B+Tree 可以很好地支持,Hash 表则无法做到。

- **空间效率**:可能导致空间利用效率不高,特别是在处理大量数据时。数据量变大时冲突也会增加。

- **需要重新构建**:哈希索引通常只存储在内存中,当数据库重启或发生崩溃时,需要重新构建。

因此,B+Tree 索引要比 Hash 表索引有着更广泛的适用场景。

### 按物理存储分类

Expand Down