Selecting top N records per group in DynamoDB

倖福魔咒の 提交于 2020-01-15 11:59:25

问题


Is NoSQL in general, and DynamoDB in particular, well suited to performing greatest-n-per-group type queries, as compared to MySQL?


回答1:


DynamoDB support only 2 index and can only be queried efficiently on these.

  1. hash key
  2. range key (optional)

Using DynamoDB to find the biggest values in a random "row" is not a good idea at all. Querying on a random row implies scanning the whole dataset which will cost you a lot of money.

Nonetheless, if your data is properly modeled, query method may be used to find the biggest range_key for a given hash_key

Here is how to proceed:

  • Set the has_key
  • Set no filter for the range_key
  • limit the result count to 1
  • scan the index backward


来源:https://stackoverflow.com/questions/11730079/selecting-top-n-records-per-group-in-dynamodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!