Reputation: 375
I have for example an artist and artworks. So in my artist table, there is only a unique hash key (artist id) and no range key. I then have a table for artworks with a hash key (artist id) and rage key (artwork id).
I am trying to understand how dynamodb will handle the artist table as far as partitions and allocating items to partitions, since each row is unique.
1) Is my only option to scan the table when I need to pull up the artist by id or what happens if i do a query with only a hash id? 2) How are all these items stored "under the hood"? How does dynamodb deal with this as far as nodes/partitions? 3) Is there a common design pattern for dealing with items that are unique and have no range key?
Thanks, have hot found anything on this exact topic yet and looking for help.
Upvotes: 1
Views: 444
Reputation: 200617
First, the "hash key" is called a "partition key" in the Amazon DynamoDB documentation. And the "range key" is called "sort key" in the documentation. It will probably help you to find info on this stuff if you use those search terms.
1) Is my only option to scan the table when I need to pull up the artist by id or what happens if i do a query with only a hash id?
Sort key is optional, you only have to pass a partition key to the query get back the record with that key. You will not need to do a full table scan in this scenario.
2) How are all these items stored "under the hood"? How does dynamodb deal with this as far as nodes/partitions?
DynamoDB will partition your data based on the partition key. I don't think they have published exactly how this works under the hood (correct me if I'm wrong). What they have said is that if each record has a unique partition key value then your data will be distributed with good uniformity.
3) Is there a common design pattern for dealing with items that are unique and have no range key?
Yes, sort key is optional in that scenario, so don't use one if you don't have one.
Reading through the Guidelines for Working with Tables section of the official documentation is really helpful for understanding this stuff.
Upvotes: 2