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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠