- Newest
- Most votes
- Most comments
You need to understand DynamoDB by first understanding its underlying data structure, which can be likened to a B+ Tree. DynamoDB is not like MongoDB in the fact it does not allow you to create access patterns which are in-efficient. All of your requests must locate items which are stored physically together, which is why contains
is not a valid function on a sort key. You must use begins_with
or between
etc.. as you can be guaranteed those items are close together. This ensures DynamoDB holds one of its key tenets, "Predictable performance at any scale".
Querying all buildings
that belong to a specific project
is as simple as creating a GSI with project
as the partition key.
SELECT building FROM mytable.myindex WHERE project = '123'
This would return you a list of buildings for that project.
Thanks for the reply,
knowing it's a B+ Tree helps a lot, thanks. That explains why it lacks query capabilities in exchange for performance. But the query you gave don't help that much, as I need 1 GSI per project as one building record can be in multiple projects.
Maybe extra records for projects??
something like PK => companyId#Project SK => buildings field1 => buildingId Extrafields => Other Project specific info
and querying for the main building record for extra info, duplicating the normally used to reduce the extra queries
Thats exactly it, you want to vertically split the items having one per building attached to the project. Use the sort key to achieve a hierarchy.
Relevant content
- Accepted Answerasked a year ago
- asked 2 months ago
- asked 6 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
Would have project as partition key and buildings as sort keys help?