Reputation: 165
I have a DynamoDB table where I need to query on two different attributes, sometimes by one, sometimes by the other one, but never by both at the same time.
Let's say I have an attribute A and attribute B, other attributes are irrelevant here.
I'm thinking of design this table with the Hash Key being the attribute A and a GSI being attribute B.
This way I always perform query
instead of scan
.
Now a question comes to my mind, which query is faster, on Attribute A (which is the Id) or on the Attribute B (GSI)?
If there is some difference I could switch, letting B as Id and A as GSI.
Thanks
Upvotes: 3
Views: 1891
Reputation: 7404
The GSI is an actual DynamoDB table with all the main table data copied.
It can be more efficient if you project only the attributes you need.
It may be less efficient considering hash keys are not unique and you may end up iterating on those results to find the desired one.
Upvotes: 1