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?
Partition Key
and/or Sort Key
from GSI point of view will result in no additional item in GSIINCLUDE
option will result in no additional item in GSII'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?
For global secondary index queries, DynamoDB calculates the provisioned read activity in the same way as it does for queries against tables. The only difference is that the calculation is based on the sizes of the index entries, rather than the size of the item in the base table.
If the value of a global secondary index key attribute is null or empty, it is better to just skip the attribute when writing it. Because global secondary indexes are stored separately, if you skip writing null or empty attributes they are not projected to the global secondary index, saving storage and write cost.
A GSI does not need to have a sort key element; we may have only a partition key (may not be unique). Unlike the primary key on a table, a GSI index does not require the indexed attributes to be unique.
You cannot use UpdateItem to update any primary key attributes. Instead, you will need to delete the item, and then use PutItem to create a new item with new attributes. Attribute values cannot be null; string and binary type attributes must have lengths greater than zero; and set type attributes must not be empty.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With