-1

So I'm following the one table design and the PK keys that are with the below format

P#product1
P#product2
P#product3
W#warehouse1
W#warehouse2
P#product4
....

With this query pattern "get all products" , I need to run a scan to get all records "begins_with = P#" and I'm not sure if this is the ideal approach. I understand Scan is resource-consuming (and I would love not to have to rely on it) Not to mention that if I want to put in limit & pagination, the scenario becomes even more cumbersome (as limit is applied before the filter). E.g: the first scan with a limit of 10 may return only 3 products, next one may only return 2 , etc..)

Is there a more straight forward approach? I was hoping to at least scan through say 87 products out of 1000 records, and will still be able to get 9 pages of 10 products per instead?

Maurice
  • 11,482
  • 2
  • 25
  • 45
Duyth
  • 25
  • 3

1 Answers1

0

I've come across other forum topics and found this solution that we can utilise Dynamodb Global Secondary Index Basically:

  • We'll set up an attribute , say entitytype(values can be product,warehouse...)
  • And create a Global Secondary Index with GSI PK : to set to that entitytype GSI SK : set to the original PK
  • We'll end up having the below in this GSI product P#product1 product P#product2 warehouse W#warehouse1

We can then query against this GSI using Query entitytype=product

Duyth
  • 25
  • 3