DynamoDB data type efficiency

0

When I query or scan a table with 10,000 rows, if I assign a field named ID as the primary key, and I perform a query or scan against that table, is it more efficient (speed) to define the Field as a Number or a String?

profile picture
Petrus
demandé il y a 2 mois131 vues
2 réponses
0

No, there is no difference which data type you use, you will get the same performance.

profile pictureAWS
EXPERT
répondu il y a 2 mois
0

There is a nuance to be aware of with this data type choice - storing a number as a number is generally going to be a better choice than storing it as a string because it is smaller in storage. This means in the bigger picture it will result in a lower cost for the storage component of your DynamoDB bill. It also means the evaluated size of the item (for metering of read and write unit consumption) could be lower. It seems unlikely that this difference will make the difference of going over the 1KB/4KB boundary for most use cases, but when you think about Query or Scan, they actually add the size of potentially many such items before rounding up to the next boundary to assess read units consumed. Depending on item size this can mean the difference between getting say 1000 items per page from Query/Scan or maybe only 500 perhaps - so the overall time taken to page through the full result set could be significantly longer. Finally, storing a number as a string means it won't work well for sorting (if you ever use it as the sort key for a secondary index, for example).

I would recommend storing numbers as numbers in almost every case. Only store them as strings if you have a really good reason to do so.

répondu il y a 2 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions