涉及嵌套属性时如何减少DynamoDB GSI项目大小

发布于 2025-02-05 08:12:41 字数 199 浏览 0 评论 0原文

DynamoDB将查询响应大小限制为1MB,因此为了最大化每个查询的项目数量,我想减少单个项目的大小。由于我通过GSI查询,因此一种自然方法是减少投影的属性数量。问题在于,我需要的一些属性是嵌套属性,而不是顶级属性。包括顶级属性在内将使GSI中的项目条目太大。

我知道没有办法在GSI中投射嵌套属性。是否有工作可以减少项目大小的工作,同时允许我在单个查询中访问嵌套属性?

DynamoDB limits query response size to 1MB, so to maximize the number of items returned per query, I would like to reduce the size of an individual item. Since I query by GSI, one natural approach is to reduce the number of attributes projected. The problem is that a few of the attributes that I need is a nested attribute and not a top-level attribute. Including the top-level attribute will make the items entries in GSI too large.

I am aware there is no way to project a nested attribute in a GSI. Is there any work-around to reduce the item size while allowing me to access nested attribute within a single query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2025-02-12 08:12:41

我想开始说您的第一个假设,DynamoDB QUERY仅限于1MB,这是不正确的。确实,查询将在读取1MB数据后返回结果,但是您可以继续获取下一个结果 - 一种称为 paging 的过程。请参阅QUERY文档,清楚地说明了如何做。

如果尽管如此,您仍然只想检索每个项目的部分而不是整个项目,这很容易做到 - 使用投影表达。如果您在查询期间传递投影表达,它将仅返回所检索的项目的一部分。它甚至使您只能像您想要的那样返回一块嵌套属性。

不过,请注意,即使您仅检索一小块大物品,您仍然会付款用于检索整个物品。这是GSI的好处,您不会使用投射表达 - 您不会获得更便宜的检索。另外,它不会帮助您进行最初的单页查询,因为1MB页面截止是在项目大小级别上发生的,而不是返回的数据长度级别。因此,您仍然需要实现分页,而不是假设一个页面总是足够的。

I want to start by saying that your first assumption, that DynamoDB Query is limited to 1MB, is incorrect. Indeed, Query will return results after having read 1MB of data, but you can continue fetching the next results - a process known as paging. Please refer to the Query documentation where it is clearly explained how to do it.

If, despite learning this, you still want to retrieve only pieces of each item and not the entire items, that's easy to do - using a ProjectionExpression. If you pass a ProjectionExpression during a Query, it will return only parts of the retrieved items. It even allows you to return only a piece of a nested attribute, exactly like you wanted.

Be aware, though, that even if you only retrieve small pieces of large items, you will still pay for retrieving the entire item. That's a benefit of GSI you don't get by using ProjectionExpression - you don't get cheaper retrieval. Also, it won't help you with the single-page query you began with, because the 1MB page cutoff happens at the item-size level, not the returned data length level. So you'll still need to implement paging and not assume that a single page is always enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文