AWS DynamoDB Secondary Indices
DynamoDB allows for quick access to items in a table if primary key values are specified
DynamoDB Secondary Indexes on a Table allow for efficient access to data that has attributes other than the primary key.
DynamoDB Secondary Indexesis a data structure containing a subset from a table.
It is associated with only one table from which it gets its data
An alternate key is required for the sort key and index partition key
You can also define projected attributes that are copied from the index into the base table along with the primary keys attributes
DynamoDB automatically maintains it
Any addition, modification, deletion or deletion of items from the base table will also affect any indexes.
The data is smaller than the main table depending on the project attributes. This helps to improve provisioned throughput performance.
They are automatically kept as sparse objects. Items will only appear in an Index if they are found in the table where the index is defined. This makes queries an index very efficient.
DynamoDB Secondary Indexes Support Two TypesGlobal secondary index – An index with a Partition Key and a Sort Key that can be different than those on the base table.
Local secondary index – An index that shares the same partition key and the base table but has a different type key.
Global Secondary Indexes – GSI
DynamoDB creates an index for the primary key attributes to provide efficient access to the data in the table. This allows applications to quickly retrieve data using primary key values.
Global Secondary Indexes (GSI), are indexes that contain partition- or composite-partition-and-sort keys, which can be different from those in the table upon which the index is based.
Global secondary index is “global” since queries on it can span all items in a table and across all partitions.
Multiple secondary indexes may be created on a single table and queries can be issued against these indexes.
Applications can benefit from having one or several secondary keys to enable efficient access to data that has attributes other than the primary key.
Non-unique attributes are supported by GSIs, which allows for more flexibility in querying.
GSIs support eventual consistency. DynamoDB handles item additions, changes, and deletions in a GSI automatically when corresponding table modifications are made asynchronously
Data in a secondary Index consists of GSI alternate keys, primary keys, and attributes that are projected or copied from the table into an index.
When querying the GSI Index, attributes that are part a table item but not the GSI keys, the primary key of a table or projected attributes, are not returned.
GSIs manage throughput independent of the table they are based upon. The provisioned throughput for the table as well as each associated GSI must be specified at creation.Read provisioned throughputprovides one Read Capacity unit with two eventually consistent reads per sec for items 4KB in size
One Write Capacity Unit provides one write per second for items less than 1KB in size.
If a new item is added to the table, write provisioned throughputconsumes 1 write unit
The table is emptied of any item that is already in use
Items that are already in use are updated to reflect projected attributes
Consumes 2 write capacity units when an item is updated for key attributes. This results in the deletion of the item and the addition of the new item to the index.
The base table is not affected by throttling on a GSI if it has insufficient read capacity.
Write operations will fail on the base table and any of its GSIs if a GSI doesn’t have sufficient write capacity. Local Secondary Indexes (LSI).
Local secondary indexes can be indexes with the same partition key and table but a different type k.
AWS DynamoDB Secondary Indices