Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 408
AciD Avatar asked Oct 23 '25 19:10

AciD


1 Answers

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.

like image 129
Ahmad Nabil Avatar answered Oct 26 '25 08:10

Ahmad Nabil