查询dynamodb中的一系列主键

编程入门 行业动态 更新时间:2024-10-27 17:15:57
本文介绍了查询dynamodb中的一系列主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想确保我没错, 根据我到目前为止所读的内容,您无法在dynamodb中查询一系列主键, 喜欢如果您有一个主键,其编号类似于客户的电话号码,那么您将无法获得主键大于3010000000或3010000000至3020000000之间的项目。 是为了清楚,我不是在说范围键,我的问题是关于主键本身的,

I want to make sure I get this right, Based on what I've read so far, you can NOT query a range of primary keys in dynamodb, like if you have a primary key which is number like the phone number of your customers, you can not get items with primary keys larger than 3010000000 or between 3010000000 and 3020000000 to make it clear, I am not talking about the range key, my questions is about the primary key itself,

因此,如果这是真的,那么会有很多用例,例如日期之间的项目,一些用户注册后点,然后...,这需要进行表扫描

so if this is true, there are lots of use cases, like items between dates, users registered after some point, and... , that requiers either table scans,

这是正确的吗?

编辑:好的,我想到的一个解决方案是,只对主键使用一个虚拟的hash_key,然后将实键(如上面的电话号码)插入范围钥匙,这行得通吗?

OK, one solution that comes to mind, would be to use only one dummy hash_key for primary key and insert the real key (like phone numbers above) as range keys, does this work?

推荐答案

是的,使用DynamoDb无法获得 hash_key 的范围。但这并不意味着您会坚持用例。

Yes, you can not get a range of hash_key with DynamoDb. But this does not mean you are stuck with your use case.

让我们以 date用例为例,并说您正在构建日志记录应用程序。您每天可能会获得很多记录。

Let's take the 'dates' use case and say your are building a logging application. You are likely to get lots of records each day.

如果将日期用作hash_key,则可以将完整的时间戳记作为range_key。这样,您可以将查询分成多个部分,并获得所需的内容。

If you use the day as the hash_key, you can put the full timestamp as the range_key. This way, you can split your query into chunks and get what you want.

当然,要获得最佳结果,您需要充分了解查询的种类。例如,典型范围是多少?使用DynamoDb以及其他key:value存储,您大部分时间都在考虑到查询的情况下对数据进行建模,与SQL在仅考虑到数据的情况下进行建模不同。

Of course, to get the optimal results, you will need to know well the kind of queries. For example, what is the typical range ? With DynamoDb, as well as other key:value store, you most of the time model your data with query in mind, unlike SQL when you model with only data in mind.

当然,如果您的商品跨度较大/较小,只需调整此系统即可。

Of course, if your items spans on larger/shorter range, just adapt this system.

关于所有对象都位于同一虚拟对象 hash_key 听起来很可怕。抱歉。我不能百分百确定它的真正工作原理,但我知道DynamoDB会对所谓的分区进行一些分片。我相信 1 hash_key< => 1个分区。此外,如果仔细阅读文档,您会发现预配置的吞吐量在各个分区之间平均分配,因此每个分区只分配了您所支付费用的一小部分。

Concerning the "all under the same dummy hash_key" sounds like a terrible idea. Sorry. I am not a hundred percent sure how it really works but I know DynamoDB does some sharding across so called partitions. I believe 1 hash_key <=> 1 partitions. Moreover, If read closely the documentation, you'll notice that the provisionned throughput is splited evenly between the partitions so that each partitions is only allocated a fraction of what you pay for.

更多推荐

查询dynamodb中的一系列主键

本文发布于:2023-10-07 17:16:01,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键   系列   dynamodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!