Database Reference
In-Depth Information
Global secondary index
Global secondary indexes are an advancement over local secondary indexes, which allow
users to query data from all over the table compared to only a single partition in the case of
the local secondary index. To understand the global secondary index better, let's consider
the same example that we had discussed earlier for the local secondary index. There, we
had created a table called Blog , which contains multiple posts from various users having
username as the hash key and date of post as the range key. We created a local sec-
ondary index topic that helped us to query all blogs for a particular topic by a given user.
But what if I want to query all blogs on a certain topic from all users? This is the exact
problem the global secondary index solves.
The global name suggests a query search on all table partitions compared to a single parti-
tion in the case of the local secondary index. Here, we can create a new hash key and an
optional range key, which is different than the table hash and range keys to get the index
working.
Some important points to note about a global secondary index are as follows:
• The global secondary index should have a hash key and an optional range key.
• The hash and range keys of a global secondary index are different from table hash
and range keys.
• The global secondary index allows you to query data across the table. It does not
restrict its search for a single data partition; hence, the name global.
• The global secondary index eventually supports only consistent reads.
• The global secondary index maintains its separate read and write capacity units,
and it does not take read and write capacity units from the table capacity units.
• Unlike the local secondary index, global ones do not have any size limits.
You can also take advantage of sparse indexes as explained in an earlier section. The fol-
lowing table shows the difference between local and global secondary indexes:
Parameter
Local secondary index
Global secondary index
Hash and
range keys
Needs both hash and range keys. The index hash
key is the same as the table hash key.
Needs hash key and optional range key. Index hash and range keys are different
than those of table keys.
Queries over complete table data, which means you can also query on other
hash keys that are not part of table hash keys.
Query scope Limited to single partition data only.
Search WWH ::




Custom Search