amazon-dynamodbdatabase-schemasecondary-indexes

Do DynamoDB Secondary Indexes Get Rewritten if no attributes change inside it?


In the AWS documentation:

Whenever a write occurs on a table, all of the table's indexes must be updated. In a write-heavy environment with large tables, this can consume large amounts of system resources. In a read-only or read-mostly environment, this is not as much of a concern. However, you should ensure that the indexes are actually being used by your application, and not simply taking up space.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.Indexes.html

However, if I am creating a global secondary index where no changes occur in the attributes of that index, will it incur a rewrite?

For example, assume that I have the following table:

KEYWORD (hash) | PHONE NUMBER (range) | ATTRIBUTE 1...N | ACCOUNT ID

KEYWORD, PHONE NUMBER and ACCOUNT ID will not change (but the entire item may be deleted).

And a global secondary index:

ACCOUNT ID (hash) | PHONE NUMBER (range) | KEYWORD

The use case is that I will need to find all of the items in the first table that all have the same ACCOUNT ID and PHONE NUMBER. I will then need the KEYWORD attribute. However, this doesn't need to happen frequently. At no time will any attribute in the global secondary index change in the original table.

The docs aren't clear (to me). I assume that the global secondary index will not have a write if the ACCOUNT ID, PHONE NUMBER and KEYWORD do not change (but other attributes may). (But that it will incur a rewrite if the original table item is deleted).


Solution

  • I believe it would depend on the projections on the GSI. If you were projecting KEYS_ONLY then I wouldn't expect another write on the GSI. But if you project ALL, which is the default, then all the data lives in the table and the GSI, so yes, it would have to update the GSI.

    https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Projections