I have a table with a hash and range complex key.
I can query an item using GetItem from AWS SDK for Java.
The GetItem returns null if it doesn't find the object, or the item as a Map.
I am looking for the fastest approach to check whether the object does exist
I was thinking maybe supplying a .withAttributesToGet such as:
GetItemResult result = dbClient.getItem(new GetItemRequest().
withTableName(TABLE_NAME).
withKey(new Key(new AttributeValue().withS(hashKey),
new AttributeValue().withS(rangeKey))).
withAttributesToGet(new ArrayList()));
Map item = result.getItem();
return (item != null);
Another optimization is to not use the SDK JSON parser and parse the response myself to quickly check if the item has returned.
Thanks
解决方案
I think there is negligible difference in speed between "getting" and checking if it exists. You can go ahead and use the GetItem itself. If the item is potentially too large, then limit the attributes being returned.
The bottle neck is in latency to reach the Dynaamo DB servers (REST API) and in fetching from the index. So Getting and checking will be similar speed. Ensure that your server issuing the call is in the same region as Dynamo DB - This has max impact on the speed.