Home > OS >  Do I need a sort key in DynamoDB if my partition key is unique?
Do I need a sort key in DynamoDB if my partition key is unique?

Time:10-15

What's the benefit of having a sort key if I already have a primary key [partition key] that is unique?

CodePudding user response:

Sort keys have two benefits:

  1. They gather related information together in one place where it can be queried efficiently. Careful design of the sort key lets you retrieve commonly needed groups of related items using range queries with operators such as begins_with, between, >, <, and so on.
  2. Composite sort keys let you define hierarchical (one-to-many) relationships in your data that you can query at any level of the hierarchy.

That being said it's completely fine to have a table with partition key only but u will probably need a sort key at some point.

  • Related