Types of Secondary Indexes

DynamoDB supports two types of indexes.

Local Secondary Index (LSI)

  • Shares the Partition Key with the base table. As an example, consider the Alternate keys illustration above - out of all the alternate keys only Key#1 can be used for LSI
  • Resides in the same partition as items
  • Shares the capacity with the table i.e., when used the consumed RRU are counted against the table and RCU for table applies in case of provisioned capacity mode.
  • Index size is restricted to 10 GB i.e., the maximum for the partition
  • WRU/WCU used when data is replicated from the base table to the index; projections makes a difference
  • Query/Scan on index allows projections with base table attributes that are not in the index projections. Doing so increases the cost of query/scan and degrades the performance.
  • Supports Strongly consistent read
  • Cannot be deleted or modified

Global Secondary Index (GSI)

  • Any key or non-key attribute(s) can be used as alternate-key for the index.
  • Does NOT share the capacity with the base table
  • No size contraint as the index spans multiple partitions
  • WRU/WCU used when data is replicated from the base table to the index; projections makes a difference
  • Does NOT support Strongly Consistent Reads
  • May be deleted/modified

Index definition

The difference is in:

  • Primary key definition An LSI must use an Alternate Sort Key and GSI has no key-schema restriction
  • Capacity setup In case of provisioned capacity mode, you need to set WCU/RCU for a GSI. Not required for LSI as it shares capacity with base table.

index-definition