问题
What is the most efficient way to get a number of how many distinct objects is stored in mine dynamodb?
Such as my objects have ten properties and I want to get a distinct count based on 3 properties.
回答1:
In case you need counters it's better to use the AtomicCounters (http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithDDItems.html). In your case, DynamoDB doesn't support out of the box keys composed out of 3 attributes, unless you concatenate them, so the option would be to create a redundant table where the key is the concatenation of those 3 attributes and each you manage those objects, also update the AtomicCounter (add, delete, update - not needed actually).
Then you just query the counter, avoiding scans. So, it's space complexity to gain speed of retrieving data.
回答2:
Perform a Scan with the appropriate ScanFilter (in this case, that the three properties are not_null), and use withCount(true) to return only the number of matching records instead of the records themselves.
See the documentation for some example code.
来源:https://stackoverflow.com/questions/15892611/how-to-get-distinct-count-on-dynamodb-on-billion-objects