Database Reference
In-Depth Information
Global secondary index
A problem arises here: is there any way in which we can create a secondary index using
both the index keys that are different from the table's primary keys? The answer is the glob-
al secondary index. The following code shows how to create the global secondary index for
this scenario:
private static GlobalSecondaryIndex
getGlobalSecondaryIndex() {
GlobalSecondaryIndex gsi = new GlobalSecondaryIndex()
.withIndexName("Idx_Pub_Edtn")
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits((long) 1)
.withWriteCapacityUnits((long) 1))
.withProjection(newProjection().withProjectionType("KEYS_ONLY"));
ArrayList<KeySchemaElement> indexKeySchema1 =
newArrayList<KeySchemaElement>();
indexKeySchema1.add(new KeySchemaElement()
.withAttributeName("Language")
.withKeyType(KeyType.HASH));
indexKeySchema1.add(new KeySchemaElement()
.withAttributeName("Edition")
.withKeyType(KeyType.RANGE));
gsi.setKeySchema(indexKeySchema1);
return gsi;
}
While deciding the attributes to be projected into a global secondary index, there are trade-
offs we must consider between provisioned throughput and storage costs. A few of these
are listed as follows:
• If our application doesn't need to query a table so often and it performs frequent
writes or updates against the data in the table, then we must consider projecting the
KEYS_ONLY attributes. The global secondary index will be the minimum size, but
it will still be available when required for the query activity.
Search WWH ::




Custom Search