Global secondary indexes
Contrary to LSIs, GSIs offer the flexibility to provide a different view of the DynamoDB table data, including the ability to use a different partition key from the base table. This means that GSIs can have entirely different partition keys and sort key attributes compared to the base table, offering significant flexibility. DynamoDB indexes the complete table data in a different view specified by your GSI key schema.
Think of a GSI as a materialized view of your DynamoDB base table data. When creating a GSI, you specify the partition key and sort key attributes, and DynamoDB handles the creation of this materialized view on demand.
To illustrate, in the e-wallet use case, if you needed to retrieve all transactions across users for a particular currency, this could be achieved by using the currency as the GSI’s partition key attribute, with the sort key being a combination of walletID
and transactionID
. This functionality may not be possible to...