5

Let's say I have a DynamoDB table T with H, R, G, and S as attributes; H being the partition/hash key and R being the range/sort key. Let's say I also have a global secondary index (GSI) that is defined with partition key as G and sort key as S.

When a query is performed using the GSI, giving paginated results, what attributes should be expected in LastEvaluatedKey? I have read the docs but it doesn't give this detail.

Nitin
  • 87
  • 12

2 Answers2

2

Looks like the LastEvaluatedKey would include all four (H, R, G and S) when the query is made on the GSI. The following seems to be the rule:

If we query on GSI, then the LastEvaluatedKey will be the compose of GSI partition key, GSI sort key, primary partition key and primary sort key.

If we query on LSI, then the LastEvaluatedKey will be the compose of LSI sort key, primary partition key and primary sort key.

Nitin
  • 87
  • 12
  • If keys are not unique then is there any way to paginate? I meant since gsi is not unique, we may get same key values as lastEvaluatedKey, so how can we proceed with this? – Vishnu Sep 01 '20 at 14:29
  • 3
    @Vishnu LastEvaluatedKey always includes keys that can identify the row uniquely – Nitin Sep 07 '20 at 17:50
0

It will return

{
  "G": "foo",
  "S": "bar"
}

In a GSI, that key is not guaranteed to be unique so keep that in mind.

tleef
  • 3,516
  • 1
  • 24
  • 34
  • 2
    If keys are not unique then is there any way to paginate? I meant since gsi is not unique, we may get same key values as lastEvaluatedKey, so how can we proceed with this? – Vishnu Sep 01 '20 at 14:29