DynamoDB:什么时候适用 1MB 的查询限制
DynamoDB: When does 1MB limit for queries apply
在 DynamoDB 的 docs 中它说:
In a Query operation, DynamoDB retrieves the items in sorted order, and then processes the items using KeyConditionExpression
and any FilterExpression
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.
这是否意味着 KeyConditionExpression
在此 1MB 限制之前应用?
的确,你的解释是正确的。使用 KeyConditionExpression
,DynamoDB 可以高效地仅获取与其条件匹配的数据,您只需为该匹配数据付费,并且 1MB 读取大小适用于匹配数据。但是对于 FilterExpression
情况就不同了:DynamoDB 没有有效的方法在实际获取所有项目之前过滤掉 non-matching 项目 then 过滤掉你没有的项目'想要。所以你支付读取整个未过滤数据(在FilterExpression
之前),最大1MB也对应未过滤数据。
如果您仍然不相信这是应该的方式,那么这里还有一个问题需要考虑:假设您的数据库中有 1 GB 的数据要扫描(或者在一个键中要扫描) Query'ed),过滤后,结果将只有 1 KB。如果您进行此查询并希望取回 1 KB,Dynamo 将需要在 returning 之前读取和处理整个 1 GB 的数据。这可能需要很长时间,而且您不知道需要多少时间,并且很可能在等待结果时超时。因此,Dynamo 确保在从磁盘读取每 1MB 的数据后向您发送 return(您为此付费 ;-))。在长查询期间,控件将 return 给你 1000 (=1 GB / 1 MB) 次,你不会有超时的机会。我不知道 1MB 的限制在这里真的有意义还是应该更多,也许我们应该对响应大小和读取量有不同的限制 - 但绝对需要对读取进行某种限制数量,即使它不会转化为大量响应。
顺便说一句,Scan
文档中有一个稍微differently-worded版本的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.
在 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.
这是否意味着 KeyConditionExpression
在此 1MB 限制之前应用?
的确,你的解释是正确的。使用 KeyConditionExpression
,DynamoDB 可以高效地仅获取与其条件匹配的数据,您只需为该匹配数据付费,并且 1MB 读取大小适用于匹配数据。但是对于 FilterExpression
情况就不同了:DynamoDB 没有有效的方法在实际获取所有项目之前过滤掉 non-matching 项目 then 过滤掉你没有的项目'想要。所以你支付读取整个未过滤数据(在FilterExpression
之前),最大1MB也对应未过滤数据。
如果您仍然不相信这是应该的方式,那么这里还有一个问题需要考虑:假设您的数据库中有 1 GB 的数据要扫描(或者在一个键中要扫描) Query'ed),过滤后,结果将只有 1 KB。如果您进行此查询并希望取回 1 KB,Dynamo 将需要在 returning 之前读取和处理整个 1 GB 的数据。这可能需要很长时间,而且您不知道需要多少时间,并且很可能在等待结果时超时。因此,Dynamo 确保在从磁盘读取每 1MB 的数据后向您发送 return(您为此付费 ;-))。在长查询期间,控件将 return 给你 1000 (=1 GB / 1 MB) 次,你不会有超时的机会。我不知道 1MB 的限制在这里真的有意义还是应该更多,也许我们应该对响应大小和读取量有不同的限制 - 但绝对需要对读取进行某种限制数量,即使它不会转化为大量响应。
顺便说一句,Scan
文档中有一个稍微differently-worded版本的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.