Is there any advantage with going L/GSI route that is a subset of sort key to prevent using sort key begins_with?
example:
Sort Key is a composite of field a
and b
and c
. There will be a frequent query over known(a)-known(b)
. Is there an efficiency/cost advantage in putting L/GSI over a field a composite field of a
and b
?
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
Begins-with is extremely efficient. If you can do a Query with that to retrieve a range of items in one go, you’re in good shape. No need for a secondary index to try to optimize further.
It basically depends on your access patterns. In general, LSI/GSI are helpful in the case where you have access pattern that won’t be efficient costly, and affecting your table availability keeping in mind that this will also cost you some money and then you have to make the cost estimation.
Other things to consider, LSI can’t be created after the table creation.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html#LSI.Creating
Code readability based on your access patterns besides RCU/WCU