Database Reference
In-Depth Information
Secondary indexes
A quick question: while writing a query in any database, keeping the primary key field as
part of the query (especially in the where condition) will return results much faster com-
pared to the other way. Why? This is because of the fact that an index will be created auto-
matically in most of the databases for the primary key field. This is the case with Dy-
namoDB also. This index is called the primary index of the table. There is no customiza-
tion possible using the primary index, so the primary index is seldom discussed.
In order to make retrieval faster, the frequently-retrieved attributes need to be made as part
of the index. However, a DynamoDB table can have only one primary index and the index
can have a maximum of two attributes (hash and range key). So for faster retrieval, the user
should be given privileges to create user-defined indexes. This index, which is created by
the user, is called the secondary index. Similar to the table key schema, the secondary index
also has a key schema. Based on the key schema attributes, the secondary index can be
either a local or global secondary index. Whenever a secondary index is created, during
every item insertion, the items in the index will be rearranged. This rearrangement will
happen for each item insertion into the table, provided the item contains both the index's
hash and range key attribute.
Search WWH ::




Custom Search