Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB query() versus getItem() for single-item retrieval based on the index

If I'm retrieving a single item from my table based on the indexed hash key, is there a performance difference between query() or getItem()?

like image 428
ensnare Avatar asked Sep 03 '12 02:09

ensnare


People also ask

What is the difference between GetItem and query in DynamoDB?

getItem retrieve via hash and range key is a 1:1 fit, the time it takes (hence performance) to retrieve it is limited by the hash and sharding internally. Query results in a search on "all" range keys. It adds computational work, thus considered slower.

What is the difference between query and scan operations in DynamoDB?

DynamoDB supports two different types of read operations, which are query and scan. A query is a lookup based on either the primary key or an index key. A scan is, as the name indicates, a read call that scans the entire table in order to find a particular result.

Which is the most efficient operation to retrieve data from a DynamoDB table?

GetItem – Retrieves a single item from a table. This is the most efficient way to read a single item because it provides direct access to the physical location of the item. (DynamoDB also provides the BatchGetItem operation, allowing you to perform up to 100 GetItem calls in a single operation.)

What is GetItem in DynamoDB?

The GetItem operation returns a set of attributes for the item with the given primary key. If there is no matching item, GetItem does not return any data and there will be no Item element in the response. GetItem provides an eventually consistent read by default.


2 Answers

getItem will be faster

getItem retrieve via hash and range key is a 1:1 fit, the time it takes (hence performance) to retrieve it is limited by the hash and sharding internally.

Query results in a search on "all" range keys. It adds computational work, thus considered slower.

like image 102
Chen Harel Avatar answered Sep 19 '22 14:09

Chen Harel


In Amazon's DynamoDB, your performances are guaranteed whatever the access method. (you pay for it).

There may be a couple a milliseconds differences on the DynamoDB servers themselves as suggested by Chen Harel but these are negligible because of the HTTP request RTT.

This said, it's a good practice to issue a GET instead of QUERY when you have enough informations to do so.

like image 41
yadutaf Avatar answered Sep 17 '22 14:09

yadutaf