在 DynamoDB 的 docs 中,它说:
In a Query operation, DynamoDB retrieves the items in sorted order, and then processes the items using
KeyConditionExpression
and anyFilterExpression
that might be present.
和:
A single Query operation can retrieve a maximum of 1 MB of data. This limit applies before any
FilterExpression
is applied to the results.
这是否意味着在 1MB 限制之前应用了
KeyConditionExpression
?
最佳答案
确实,你的解释是正确的。使用 KeyConditionExpression
,DynamoDB 可以高效地仅获取符合其条件的数据,您只需为匹配数据付费,1MB 读取大小适用于匹配数据。但是使用 FilterExpression
情况就不同了:DynamoDB 没有有效的方法来过滤掉不匹配的项目,然后再实际获取所有不匹配的项目,然后过滤掉您不想要的项目。所以你 支付 来读取整个未过滤的数据(在 FilterExpression
之前),最大 1MB 也对应于未过滤的数据。
如果您仍然不相信这是应该的方式,那么这里有另一个需要考虑的问题:想象一下,您的数据库中有 1 GB 的数据要被扫描(或在单个键中被查询),过滤后,结果将仅为 1 KB。如果您进行此查询并希望返回 1 KB,Dynamo 将需要在返回之前读取和处理整个 1 GB 的数据。这可能需要很长时间,而且您不知道需要多少时间,并且在等待结果时可能会超时。因此,Dynamo 会确保在从磁盘读取每 1MB 数据后返回给您(您为此付费 ;-))。在长查询期间,控制将返回给您 1000 (=1 GB/1 MB) 次,您将没有机会超时。我不知道 1MB 的限制在这里是否真的有意义,还是应该更多,我不知道,也许我们应该对响应大小和读取量设置不同的限制 - 但绝对需要对读取进行某种限制数量,即使它不会转化为大量响应。
顺便说一句,Scan
文档中包含了对 1MB 限制的解释的措辞略有不同的版本,也许您会发现它比 Query
文档中的版本更清晰:
A single Scan operation will read up to the maximum number of items set (if using the Limit parameter) or a maximum of 1 MB of data and then apply any filtering to the results using FilterExpression.
关于amazon-web-services - DynamoDB : When does 1MB limit for queries apply,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56631433/