例如(使用 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/