How does DynamoDB GSI treat missing attributes?

Viewed 10058

Looking at this DynamoDB documentation about GSI, I found the following comment:

A global secondary index only keeps track of data items where its key attribute(s) actually exist.

Which of the following does this exactly mean?

  1. Missing Partition Key and/or Sort Key from GSI point of view will result in no additional item in GSI
    e.g.) "GameTitle" and "TopScore" are required
  2. Missing data for any attributes you specify as a part of GSI with INCLUDE option will result in no additional item in GSI
    e.g.) All attributes projected to GSI even "Wins", "Loses" are required

I'm suspecting the "key attribute(s)" refer to the 1., and any missing data from INCLUDE option point of view will simply come back as empty when GSI is queried, but wanted to check if my understanding is correct.

Also, would there be no difference between GSI and LSI in this space?

1 Answers

In the page you linked to Global Secondary Indexes

Then next two lines from what you quoted are:

A global secondary index only keeps track of data items where its key attribute(s) actually exist. For example, suppose that you added another new item to the GameScores table, but only provided the required primary key attributes:
Because you didn't specify the TopScore attribute, DynamoDB would not propagate this item to GameTitleIndex.

So if you have a GSI over attribute GSIKey and you add a record to the table without that attribute, the GSI will not get an entry for that record.

If you add a record with a GSIKey, then the GSI will have an entry for that record.

Any additional projected attributes will either be there or not. Same as with the table itself.

The technical term for this is a sparse index; it does not have to contain as many entries as the base table.

Local secondary index are also sparse.

Related