python - 当我在没有过滤器的情况下在 Dynamodb 中执行 scan() 并仅检索 10 个对象时,它是否仍然访问整个数据库?

标签 python amazon-web-services boto amazon-dynamodb

例如(使用 Boto):

import boto

db = boto.connect_dynamodb()

table = db.get_table('MyTable')
res = table.scan(attributes_to_get=['id'], max_results=10)

for i in res:
    print i

如果我的表中有 1,000 个对象,它会扫描所有对象,还是在 10 个之后停止?如果这确实读取了所有 1,000 个对象,我如何让它只读取前 10 个?

最佳答案

根据 capacity unit calculation 上的文档,每个请求最多只能分析 1MB 的数据。

In case of a scan operation, it is not the size of items returned by scan, rather it is the size of items evaluated by Amazon DynamoDB. That is, for a scan request, Amazon DynamoDB evaluates up to 1 MB of items and returns only the items that satisfy the scan condition.

对于“只有”1,000 个项目的表,理论上每次都会解析所有表。希望“limit”参数(最大值为 100)允许提前停止进程,以便最多返回 limit 个项目。

如果您的请求不涉及任何条件,扫描的项目计数将是结果的数量。否则,它可能会大很多,但扫描项目的累积大小不能超过 1MB 的边界。

对于扫描的操作,亚马逊会认为你消费了

consumed_capacity = math.ceil(sum(parsed_data_size)/1KB)

但是请不要相信我的话:

import boto
db = boto.connect_dynamodb()

# Notice the "layer1" operation
res = db.layer1.scan('MyTable', attributes_to_get=['id'], limit=10)

print res['ScannedCount']

关于python - 当我在没有过滤器的情况下在 Dynamodb 中执行 scan() 并仅检索 10 个对象时,它是否仍然访问整个数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12183141/

相关文章:

Mongodb EC2 EBS 备份

amazon-web-services - 如何通过boto获取S3 key 的创建日期?

python - 如何从字节串中恢复二维 numpy.array?

python - 如何将两个列表合并为 python 中的一系列列?

python - Python与CV2视频同步播放音频

amazon-web-services - AWS Amplify - 配置的安全性

python - Python 中的负回顾 RE

java - AWS Lambda 中的 Oracle 数据库连接

ruby-on-rails - AWS 负载均衡器 EC2 运行状况检查请求超时失败

python - 如何使用 boto 将文件上传到 S3 存储桶中的目录