How should the developer write the DynamoDB query?
Add a local secondary index (LSI) during table creation. Query the LSI by using eventually consistent reads.
Add a local secondary index (LSI) during table creation. Query the LSI by using strongly consistent reads.
Add a global secondary index (GSI) during table creation. Query the GSI by using eventually consistent reads.
Add a global secondary index (GSI) during table creation. Query the GSI by using strongly consistent reads.
Explanations:
Adding a local secondary index (LSI) allows queries with a different sort key for the same partition key, but it does not provide a way to query the latest data effectively if write operations happen frequently. Using eventually consistent reads does not guarantee the latest data.
Adding a local secondary index (LSI) enables querying by a different sort key while maintaining the same partition key, which is useful for fetching the latest data. Strongly consistent reads ensure that the query reflects all recent write operations.
A global secondary index (GSI) allows querying by different partition and sort keys but does not meet the requirement of querying based on the original partition key and a different sort key. Additionally, eventually consistent reads may not show the most recent data.
While a global secondary index (GSI) can query based on different keys, it does not allow queries using the original partition key with a different sort key. Strongly consistent reads on a GSI also may not provide the latest data immediately after writes, leading to potential stale reads.