I have a dynamodb table and a list of all primary keys of the table.
a sample item might a PK of "foo_12424" and SK of "bar_32456"
I want to get all items with sk that starts with the prefix "bar_3"
I can think of doing this in two ways:
From my understanding scan is very inefficient my thought was that querying the sort key would be more efficient since it doesn't go through all items but I'm wondering if the overhead of looping over all primary key negates this advantage?
Essentially what you need here is global sort order based on SK. For that, its often useful to have an index with a common attribute as PK, and then your requests become highly efficient and fast.
You can understand more from the blog post here.
GSI_PK | SK | PK |
---|---|---|
1 | bar_32456 | foo_12424 |
1 | bar_33453 | foo_12111 |
1 | bar_34344 | foo_12222 |