3
votes

I am using boto3 to query DynamoDB. And I have heard that table.query() is more efficient that table.scan() I was wondering if there is a way to check if the value exists using query() method?

response = table.scan(
        FilterExpression=Attr('attribute').exists()

If it is not possible to check using query() is there any other method that is more efficient than scan()?

This question is not a duplicate - I am looking for a way to optimize querying for existing/non existing attributes of query() or scan()

1
@Chris Nauroth I don't think it is a duplicate as it talks about scan() and my question is about query() - BanzaiTokyo

1 Answers

1
votes

It seems that query() is more efficient than scan() because it works with hash key only, and the query must match base table schema. That is the reason for it to be so efficient.

Therefore it is not possible to scan() for attributes that are not in the base schema.