如何在 DynamoDB 中立即获取表的行数?
问题描述
我正在使用 boto.dynamodb2
,看来我可以使用 Table.query_count()
.但是,当没有应用查询过滤器时,它会引发异常.
I'm using boto.dynamodb2
, and it seems I can use Table.query_count()
. However it had raised an exception when no query filter is applied.
我能做些什么来解决这个问题?
What can I do to fix this?
顺便说一句,boto.dynamodb2.table.Table.Query
可以使用的过滤器文档在哪里?我试图搜索它,但什么也没找到.
BTW, where is the document of filters that boto.dynamodb2.table.Table.Query
can use? I tried searching for it but found nothing.
解决方案
有两种方法可以在 DynamoDB 中获取行数.
There are two ways you can get a row count in DynamoDB.
第一个是执行全表扫描并在执行过程中计算行数.对于任何合理大小的表,这通常是一个可怕的想法,因为它会消耗您预置的所有读取吞吐量.
The first is performing a full table scan and counting the rows as you go. For a table of any reasonable size this is generally a horrible idea as it will consume all of your provisioned read throughput.
另一种方法是使用 Describe Table 请求来估计表中的行数.这将立即返回,但只会根据 AWS 文档定期更新.
The other way is to use the Describe Table request to get an estimate of the number of rows in the table. This will return instantly, but will only be updated periodically per the AWS documentation.
指定索引中的项目数.DynamoDB 更新了这个值大约每六个小时.最近的变化可能不是反映在这个值中.
The number of items in the specified index. DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this value.
相关文章