DynamoDB count operation capacity units consumption
Asked Answered
B

1

7

If I'm not mistaken, to perform a count of items, in DynamoDB we have to use the query action and provide Select: 'COUNT' as parameter. Let's consider that I'd like to count the number of items that have a certain partition key. Given that we have to use the query action, does that mean the following?:

  1. Even though we're returning only the count, the consumed read capacity units will correspond to the size of all the items with that partition key.
  2. If the size of the items that have the given partition key exceeds 1MB, the count will be partial, will only consider the items up to 1MB and the operation will be paginated.
Bonzer answered 7/6, 2016 at 11:43 Comment(0)
M
11

The answer is yes, to both your questions.

That is apparent from these two points from the documentation:

  • Distinction between Count and ScannedCount:

If you used a QueryFilter in the request, then Count is the number of items returned after the filter was applied, and ScannedCount is the number of matching items before the filter was applied.

If you did not use a filter in the request, then Count and ScannedCount are the same.

  • The fact that DynamoDB looks at Count as just another attribute that can be returned:

You can retrieve all item attributes, specific item attributes, the count of matching items, or in the case of an index, some or all of the attributes projected into the index.

Matriarchy answered 7/6, 2016 at 16:54 Comment(1)
so what's the most common/performing way to keep a counter of records by partition key? Caching the count somewhere else by using DynamoDB Streams + Lambda? This is a huge limitation, counting records it's a really common task. I would understand that AWS guys charged for more RCUs if the count involves any other attribute that's not the partition key, but given that we're querying only an indexed attribute...Bonzer

© 2022 - 2024 — McMap. All rights reserved.