2

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).

Jeff Vdovjak
  • 1,833
  • 16
  • 21

1 Answers1

1

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

Jason Wadsworth
  • 8,059
  • 19
  • 32
  • Thanks for that link and thoughts. I agree that if I projected ALL it would definitely write; and if I projected KEYS_ONLY it definitely would not write. However, what if you INCLUDE the one attribute, but it doesn't change. It makes sense to me that it would not write. – Jeff Vdovjak Jan 29 '20 at 01:15
  • Reading further through the documentation does indeed confirm your answer. If you have fields that exist in both the base table and the GSI but they do not change, the GIS will not be updated. – Jeff Vdovjak Jan 29 '20 at 01:34
  • 1
    You can actually test this theory by using the ReturnConsumedCapacity parameter of the request, and confirming whether a write that shouldn't need to write to the GSI actually doesn't. If you do this experiment, please report your findings back here! Thanks. – Nadav Har'El Jan 29 '20 at 08:30
  • Nadav, I'm just learning DynamoDB and working through the docs (as well as learning Node.JS so I can use Lambda) for a new project. But I will certainly do that! (Great idea!). I'll report back when I do -- but I believe it will not be for awhile. – Jeff Vdovjak Jan 29 '20 at 14:29