Database Reference
In-Depth Information
Secondary indexes
Primary indexes are created by DynamoDB by default. Along with those indexes, the user
can create up to five secondary indexes for a table. There are two kinds of secondary in-
dexes:
• The first is the local secondary index (in which the hash key of the index must be
the same as that of the table)
• The second is the global secondary index (in which the hash key can be any field)
In both of these secondary index types, the range key can be a field, which the user needs
to create the index for.
In the case of the local secondary index, the grouping will always take place on the hash
key attribute, whereas the ordering takes place on the nonprimary key attribute. A quick
question: in DynamoDB, except for primary key attributes, all other attributes are optional
for an item. So where do these index attributes fall, in optional attributes or mandatory at-
tributes? The answer is that local secondary index attributes are also optional attributes. If
an item does not include this attribute, then that item will not be indexed, it's as simple as
that.
We will take a look at an example in the following table:
Let's say that we are creating a local secondary index on the PubDate attribute. Let's
name this index Idx_PubDate . The index will look as shown in the next table. This is
Search WWH ::




Custom Search