hashtable - dynamodb 表中的哈希范围有什么用?

标签 hashtable amazon-dynamodb

我是 dynamodb (ddb) 的新手。我正在查看它的文档,它说添加哈希键和哈希范围键。在文档中,它说 ddb 将在哈希键上创建一个无序索引,并在哈希范围上创建一个排序索引。

拥有这 2 个 key 而不是只有一个 key 的目的是什么?是因为第一个键的使用方式如下: 一个哈希表,其中包含: key - 哈希范围中每个值的键范围

第二个哈希表 哈希范围键 - 实际数据值。

这将有助于隔离数据并加快查找速度。但为什么只有 2 层 HashMap,我可以对 n 层执行此操作并获得更快的查找速度。

提前谢谢您。

最佳答案

问:“拥有这 2 个 key 而不是只有一个 key 的目的是什么?”

就数据模型而言,哈希键允许您唯一地标识表中的记录,范围键可以选择用于对通常一起检索的多条记录进行分组和排序。示例:如果您定义一个聚合来存储订单项,则 OrderId 可以是您的哈希键,OrderItemId 可以是范围键。您可以在下面找到这两个键的使用的正式定义:

"Composite Hash Key with Range Key allows the developer to create a primary key that is the composite of two attributes, a 'hash attribute' and a 'range attribute.' When querying against a composite key, the hash attribute needs to be uniquely matched but a range operation can be specified for the range attribute: e.g. all orders from Werner in the past 24 hours, or all games played by an individual player in the past 24 hours." [VOGELS]

因此,范围键数据模型添加了分组功能,但是,这两个键的使用也对存储模型:

"Dynamo uses consistent hashing to partition its key space across its replicas and to ensure uniform load distribution. A uniform key distribution can help us achieve uniform load distribution assuming the access distribution of keys is not highly skewed." [DDB-SOSP2007]

哈希键不仅可以唯一标识记录,而且还是确保负载分配的机制。 范围键(使用时)有助于指示主要一起检索的记录,因此,也可以针对此类需求优化存储。

问:“但是为什么只有 2 层 HashMap?我可以对 n 层执行此操作并获得更快的查找速度。”

拥有多层查找将增加在集群环境中有效运行数据库的指数级复杂性,这是大多数 NOSQL 数据库最重要的用例之一。数据库必须具有高可用性、防故障、有效可扩展,并且仍然可以在分布式环境中执行。

"One of the key design requirements for Dynamo is that it must scale incrementally. This requires a mechanism to dynamically partition the data over the set of nodes (i.e., storage hosts) in the system. Dynamo’s partitioning scheme relies on consistent hashing to distribute the load across multiple storage hosts."[DDB-SOSP2007]

这始终是一个权衡,您在 NOSQL 数据库中看到的每一个限制很可能都是由存储模型要求引入的。尽管关系数据库在数据建模方面非常灵活,但在分布式环境中运行时存在一些限制。

选择正确的键来表示数据是设计过程中最关键的方面之一,它直接影响应用程序的性能、规模和成本。


脚注:

  • 数据模型是我们感知和操作数据的模型。它描述了我们如何与数据库中的数据交互[FOWLER]。换句话说,它是您抽象数据模型的方式、对实体进行分组的方式、选择作为主键的属性等

  • 存储模型描述了数据库如何在内部存储和操作数据[FOWLER]。尽管您无法直接控制这一点,但您当然可以通过了解数据库内部的工作方式来优化数据的检索或写入方式。

关于hashtable - dynamodb 表中的哈希范围有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29178855/

相关文章:

java - 具有读取线程局部变量的键回调的静态哈希表

amazon-web-services - dynamodb updateitem 与条件表达式返回项目是否已更新

nosql - 何时使用dynamoDB -UseCases

amazon-web-services - 在同一个 lambda 函数中访问来自不同帐户的两个表

创建具有快速插入、删除、成员资格测试和随机选择的数据结构

powershell - 从 powershell 对象中选择元素

java - 初始化 HashMap 的最佳方式

c - "array type has incomplete element type"是什么意思?

amazon-web-services - 内存存储 (Elasticache) 与持久数据存储 (Dynamodb) 之间的读/写延迟比较(以高级数字表示)

amazon-web-services - AWS 文档数据库中的事务