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
已提问 2 个月前131 查看次数
2 回答
0

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

profile pictureAWS
专家
已回答 2 个月前
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.

已回答 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则