gpt4 book ai didi

database - 从 DynamoDB 中获取值

转载 作者:太空狗 更新时间:2023-10-30 01:41:01 24 4
gpt4 key购买 nike

我刚刚开始研究 Amazon 的 DynamoDB。显然,可伸缩性很有吸引力,但我正试图摆脱 SQL 模式,进入非 SQL 模式。可以这样做吗(具有 dynamodb 的所有可扩展性优势):

有大量条目(比如 5 - 1000 万)由某个数字索引。每个条目中的一个字段将是创建日期。 dynamo db 是否有一种有效的方法可以为我的网络应用程序提供两个日期之间创建的所有条目?

一个更简单的问题 - dynamo db 可以给我所有字段匹配特定数字的条目吗?也就是说,将有另一个字段是数字,为了参数的缘故,让我们说在 0 到 10 之间。我可以要求 dynamodb 给我所有具有值的条目,例如6?

这两个查询是否都需要扫描整个数据集(我认为这是给定数据集大小的问题?)

非常感谢

最佳答案

Is there an effective way for dynamo db to give my web app all the entries created between two dates?

是的,请查看 Primary KeyAmazon DynamoDB 数据模型 中的概念,特别是哈希和范围类型主键:

In this case, the primary key is made of two attributes. The first attributes is the hash attribute and the second one is the range attribute. Amazon DynamoDB builds an unordered hash index on the hash primary key attribute and a sorted range index on the range primary key attribute. [...]

列出的示例完全符合您的用例,即 Reply ( Id, ReplyDateTime, ... ) 表有助于使用 Hash and Range 类型的主键散列属性 Id 和范围属性 ReplyDateTime

您将通过 Query 使用它API,请参阅 RangeKeyCondition 了解详细信息和 Querying Tables in Amazon DynamoDB对于各自的例子。

can dynamo db give me all entries in which a field matches a certain number. [...] Can I ask dynamodb to give me all the entries which have value e.g. 6?

这也是可能的,尽管是通过 Scan仅 API(即确实需要读取表中的每个项目),请参阅 ScanFilter 了解详细信息和 Scanning Tables in Amazon DynamoDB对于各自的例子。

Do both of these queries need a scan of the entire dataset (which I assume is a problem given the dataset size?)

如前所述,第一种方法使用查询,而第二种方法需要扫描,而且通常,查询操作比扫描操作更有效 - 这是一个很好的入门建议,尽管细节更复杂并且取决于您的用例,请参阅 Query and Scan in Amazon DynamoDB 中的扫描和查询性能部分概述:

For quicker response times, design your tables in a way that can use the Query, Get, or BatchGetItem APIs, instead. Or, design your application to use scan operations in a way that minimizes the impact on your table's request rate. For more information, see Provisioned Throughput Guidelines in Amazon DynamoDB.

因此,与往常一样,在应用 NoSQL 解决方案时,您可能需要调整架构以适应这些限制。

关于database - 从 DynamoDB 中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9166306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com