什么是哈希和范围主键? [英] What is Hash and Range Primary Key?

查看:442
本文介绍了什么是哈希和范围主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解这里的主键是什么 -

I am not able to understand what is Range primary key here -

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key

它是如何工作的?

它们是什么意思 - 无序哈希索引哈希属性和排序范围范围属性上的索引

what do they mean by - "unordered hash index on the hash attribute and a sorted range index on the range attribute"?

推荐答案

散列和范围主键< DynamoDB中的行具有由哈希范围键组成的唯一主键。例如,使用散列键 X 和范围键 Y ,您的主键有效地是 XY 。您也可以为同一个哈希键使用多个范围键,但组合必须是唯一的,例如 XZ XA 。让我们使用他们的例子为每种类型的表:

"Hash and Range Primary Key" means that a single row in DynamoDB has a unique primary key made up of both the hash and the range key. For example with a hash key of X and range key of Y, your primary key is effectively XY. You can also have multiple range keys for the same hash key but the combination must be unique, like XZ and XA. Let's use their examples for each type of table:


Hash主键 - 主键由一个属性,散列
属性。例如,ProductCatalog表可以将ProductID作为
的主键。 DynamoDB在这个
主键属性上构建一个无序的哈希索引。

Hash Primary Key – The primary key is made of one attribute, a hash attribute. For example, a ProductCatalog table can have ProductID as its primary key. DynamoDB builds an unordered hash index on this primary key attribute.

这意味着每一行都是从这个值。 DynamoDB中的每一行都会有此属性的必填唯一值。无序哈希索引意味着什么说 - 数据不是有序的,你不给任何保证如何存储数据。 您无法对无序索引进行查询,例如获取产品ID大于X的所有行。您根据散列键写入和获取项目。例如,获取该表中具有ProductID X的行。您正在对无序索引进行查询,所以您的反对基本是键值查找,速度非常快,并且使用非常少的吞吐量。

This means that every row is keyed off of this value. Every row in DynamoDB will have a required, unique value for this attribute. Unordered hash index means what is says - the data is not ordered and you are not given any guarantees into how the data is stored. You won't be able to make queries on an unordered index such as Get me all rows that have a ProductID greater than X. You write and fetch items based on the hash key. For example, Get me the row from that table that has ProductID X. You are making a query against an unordered index so your gets against it are basically key-value lookups, are very fast, and use very little throughput.


Hash和Range主键 - 主键由两个
属性组成。第一个属性是哈希属性,第二个
属性是范围属性。例如,论坛线程表
可以有ForumName和Subject作为其主键,其中ForumName是
哈希属性,Subject是范围属性。 DynamoDB构建
哈希属性上的无序哈希索引和范围属性的排序范围索引

Hash and Range Primary Key – The primary key is made of two attributes. The first attribute is the hash attribute and the second attribute is the range attribute. For example, the forum Thread table can have ForumName and Subject as its primary key, where ForumName is the hash attribute and Subject is the range attribute. DynamoDB builds an unordered hash index on the hash attribute and a sorted range index on the range attribute.

这表示每行的主键是散列和范围键的组合。如果您同时具有哈希和范围键,或者您可以针对已排序范围索引进行查询,则可以对单个行进行直接获取。例如,获取从表格中获取具有大于Y的范围键的哈希键X的所有行或其他查询。与对未编制索引的字段进行扫描和查询相比,它们具有更好的性能和更少的容量使用。从其文档

This means that every row's primary key is the combination of the hash and range key. You can make direct gets on single rows if you have both the hash and range key, or you can make a query against the sorted range index. For example, get Get me all rows from the table with Hash key X that have range keys greater than Y, or other queries to that affect. They have better performance and less capacity usage compared to Scans and Queries against fields that are not indexed. From their documentation:


查询结果总是按范围键排序。如果
的数据类型的范围键是Number,结果将按数字顺序返回;
否则,结果以ASCII字符代码
的值顺序返回。默认情况下,排序顺序为升序。要颠倒顺序,
将ScanIndexForward参数设置为false

Query results are always sorted by the range key. If the data type of the range key is Number, the results are returned in numeric order; otherwise, the results are returned in order of ASCII character code values. By default, the sort order is ascending. To reverse the order, set the ScanIndexForward parameter to false

我可能错过了一些我键入的内容,只刮了表面。还有很多更多要考虑的因素当使用DynamoDB表(吞吐量,一致性,容量,其他索引,密钥分配等)时。您应该查看示例表和数据页面

I probably missed some things as I typed this out and I only scratched the surface. There are a lot more aspects to take into consideration when working with DynamoDB tables (throughput, consistency, capacity, other indices, key distribution, etc.). You should take a look at the sample tables and data page for examples.

这篇关于什么是哈希和范围主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆