Some applications might have to perdevelop many kinds of queries, using a selection of different features as query criteria. To assistance these needs, you have the right to develop one or more worldwide additional indexes and problem Query requests against these indexes in Amazon DynamoDB.




You are watching: Which of the following statements is true of global consistency?

Scenario: Using a Global Secondary Index

To illustrate, consider a table called GameScores that tracks individuals and also scores for a mobile gaming application. Each item in GameScores is determined by a partition crucial (UserId) and a type crucial (GameTitle). The following diagram mirrors just how the items in the table would certainly be arranged. (Not all of the qualities are displayed.)


*

Now suppose that you wanted to write a leaderboard application to screen peak scores for each game. A query that specified the essential attributes (UserId and GameTitle) would certainly be exceptionally efficient. However before, if the application necessary to retrieve data from GameScores based upon GameTitle just, it would certainly need to use a Shave the right to operation. As more items are added to the table, scans of all the data would certainly come to be slow and also inreliable. This makes it hard to answer questions such as the following:


What is the height score ever tape-recorded for the game Meteor Blasters?

Which user had the greatest score for Galaxy Invaders?

What was the highest possible proportion of wins vs. losses?


To rate up queries on non-crucial attributes, you can produce a worldwide additional index. A international second index includes an option of characteristics from the base table, however they are arranged by a main crucial that is different from that of the table. The index crucial does not should have actually any kind of of the vital characteristics from the table. It does not also need to have the very same vital schema as a table.

For instance, you can develop a global additional index named GameTitleIndex, via a partition key of GameTitle and also a sort essential of TopScore. The base table"s main crucial features are always projected into an index, so the UserId attribute is additionally current. The adhering to diagram shows what GameTitleIndex index would look choose.


*

Now you deserve to query GameTitleIndex and easily achieve the scores for Meteor Blasters. The results are ordered by the kind essential worths, TopScore. If you set the ScanIndexForward parameter to false, the results are returned in descending order, so the greatest score is went back first.

Every worldwide secondary index have to have a partition crucial, and also can have actually an optional sort essential. The index essential schema can be various from the base table schema. You might have a table through a straightforward major essential (partition key), and create an international second index via a compowebsite major vital (partition key and type key)—or vice versa. The index vital attributes can consist of any top-level String, Number, or Binary attributes from the base table. Other scalar kinds, record kinds, and collection types are not enabled.

You deserve to task other base table features into the index if you desire. When you query the index, DynamoDB deserve to retrieve these projected qualities efficiently. However, worldwide additional index queries cannot fetch qualities from the base table. For example, if you query GameTitleIndex as shown in the previous diagram, the query can not access any kind of non-essential characteristics various other than TopScore (although the key features GameTitle and also UserId would immediately be projected).

In a DynamoDB table, each key worth must be distinctive. However, the essential values in a worldwide additional index perform not must be distinct. To show, mean that a game named Comet Quest is particularly challenging, with many kind of new individuals trying but failing to gain a score above zero. The complying with is some information that might recurrent this.


When this information is added to the GameScores table, DynamoDB propaentrances it to GameTitleIndex. If we then query the index utilizing Comet Quest for GameTitle and 0 for TopScore, the complying with data is returned.



Only the items via the mentioned crucial values show up in the response. Within that set of information, the items are in no particular order.

A international second index just tracks data items wbelow its key qualities actually exist. For example, expect that you included an additional new item to the GameScores table, however just provided the compelled main vital qualities.


Because you didn"t specify the TopScore attribute, DynamoDB would not propagate this item to GameTitleIndex. Thus, if you queried GameScores for all the Comet Quest items, you would certainly acquire the complying with four items.


*

A equivalent query on GameTitleIndex would still rerevolve three items, rather than four. This is bereason the item via the nonexistent TopScore is not propagated to the index.



Attribute Projections

A projection is the collection of attributes that is duplicated from a table right into an additional index. The partition essential and sort crucial of the table are always projected into the index; you deserve to job other characteristics to support your application"s query demands. When you query an index, Amazon DynamoDB have the right to access any type of attribute in the forecast as if those characteristics were in a table of their very own.

When you develop a secondary index, you must specify the attributes that will be projected into the index. DynamoDB gives 3 various options for this:


KEYS_ONLY – Each item in the index is composed just of the table partition essential and also type vital worths, plus the index key values. The KEYS_ONLY alternative outcomes in the smallest feasible secondary index.

INCLUDE – In enhancement to the features explained in KEYS_ONLY, the second index will include various other non-key attributes that you specify.

ALL – The additional index consists of all of the features from the source table. Because all of the table data is copied in the index, an ALL projection outcomes in the biggest possible second index.


In the previous diagram, GameTitleIndex has just one projected attribute: UserId. So while an application can successfully determine the UserId of the optimal scorers for each game making use of GameTitle and TopScore in queries, it can"t properly recognize the highest possible ratio of wins vs. losses for the peak scorers. To carry out so, it would certainly have to perdevelop a second query on the base table to fetch the wins and losses for each of the top scorers. A more reliable method to support queries on this data would certainly be to job these characteristics from the base table right into the global secondary index, as displayed in this diagram.


Because the non-essential characteristics Wins and Losses are projected right into the index, an application deserve to recognize the wins vs. losses ratio for any kind of game, or for any kind of combicountry of game and user ID.

When you pick the qualities to project into a worldwide secondary index, you must consider the tradeoff between provisioned throughput prices and storage costs:


If you should access simply a couple of qualities via the lowest possible latency, consider projecting just those characteristics right into a global second index. The smaller the index, the much less that it costs to save it, and the less your create costs are.

If your application commonly accesses some non-crucial attributes, you must consider projecting those features right into an international additional index. The added storage costs for the global second index balance out the price of percreating frequent table scans.

If you should access a lot of of the non-crucial characteristics on a constant basis, you have the right to task these attributes—or even the whole base table— into an international additional index. This gives you maximum flexibility. However before, your storage price would certainly rise, or also double.

If your application demands to query a table infrequently, yet should perdevelop many type of writes or updates versus the information in the table, think about projecting KEYS_ONLY. The global secondary index would certainly be of minimal size, however would still be accessible when needed for query activity.


Reading File from a Global Secondary Index

You can retrieve items from an international additional index utilizing the Query and also Shave the right to operations. The GetItem and GetBatchItem operations can not be supplied on a worldwide additional index.

Querying a Global Secondary Index

You can usage the Query operation to accessibility one or even more items in an international second index. The query should specify the name of the base table and the name of the index that you want to use, the features to be reverted in the query outcomes, and also any type of query problems that you want to use. DynamoDB have the right to rerevolve the results in ascfinishing or descending order.

Consider the following data went back from a Query that repursuits gaming information for a leaderboard application.


"TableName": "GameScores", "IndexName": "GameTitleIndex", "KeyConditionExpression": "GameTitle = :v_title", "ExpressionAttributeValues": ":v_title": "S": "Meteor Blasters" , "ProjectionExpression": "UserId, TopScore", "ScanIndexForward": false In this query:


DynamoDB accesses GameTitleIndex, using the GameTitle partition crucial to situate the index items for Meteor Blasters. All of the index items with this crucial are stored nearby to each other for quick retrieval.

Within this game, DynamoDB uses the index to accessibility all of the user IDs and also top scores for this game.

The results are went back, sorted in descending order because the ScanIndexForward parameter is collection to false.


Scanning a Global Secondary Index

You can usage the Scan operation to retrieve every one of the data from an international second index. You have to provide the base table name and the index name in the request. With a Scan, DynamoDB reads all of the information in the index and returns it to the application. You can also research that only some of the information be returned, and that the staying information need to be discarded. To do this, usage the FilterExpression parameter of the Sdeserve to procedure. For more indevelopment, see Filter Expressions for Shave the right to.

Data Synchronization Between Tables and Global Secondary Indexes

DynamoDB immediately synchronizes each global secondary index via its base table. When an application writes or deletes items in a table, any kind of international additional indexes on that table are updated asynchronously, using an inevitably consistent design. Applications never before create straight to an index. However, it is vital that you understand the implications of just how DynamoDB maintains these indexes.

Global second indexes inherit the read/write capacity mode from the base table. For even more information, watch Considerations When Changing Read/Write Capacity Setting.

When you develop a worldwide secondary index, you specify one or even more index essential features and their data types. This suggests that whenever before you create an item to the base table, the data species for those features should enhance the index crucial schema"s data types. In the situation of GameTitleIndex, the GameTitle partition vital in the index is identified as a String data kind. The TopScore kind key in the index is of form Number. If you attempt to include an object to the GameScores table and also specify a different data kind for either GameTitle or TopScore, DynamoDB returns a ValidationException bereason of the data kind misenhance.

When you put or delete items in a table, the worldwide second indexes on that table are updated in an eventually constant fashion. Changes to the table data are propagated to the global second indexes within a fraction of a second, under normal conditions. However before, in some unlikely failure scenarios, much longer propagation delays might happen. Thus, your applications need to anticipate and also handle cases where a query on an international additional index returns results that are not approximately date.

If you write an object to a table, you don"t need to specify the features for any kind of international second index kind key. Using GameTitleIndex as an instance, you would certainly not need to specify a worth for the TopScore attribute to compose a new item to the GameScores table. In this case, DynamoDB does not write any data to the index for this specific item.

A table with many type of global additional indexes incurs better prices for create activity than tables via fewer indexes. For even more indevelopment, check out Provisioned Throughput Considerations for Global Secondary Indexes.

Provisioned Throughput Considerations for Global Secondary Indexes

When you create an international second index on a provisioned mode table, you have to specify read and compose capacity units for the supposed workfill on that index. The provisioned throughput settings of a worldwide secondary index are sepaprice from those of its base table. A Query operation on an international secondary index consumes read capacity units from the index, not the base table. When you put, upday or delete items in a table, the global second indexes on that table are also updated. These index updates consume compose capacity devices from the index, not from the base table.

For example, if you Query an international second index and exceed its provisioned read capacity, your research will certainly be throttled. If you perdevelop hefty compose task on the table, however a global second index on that table has actually inenough compose capacity, the create activity on the table will be throttled.


To stop potential throttling, the provisioned create capacity for a global second index must be equal or better than the compose capacity of the base table because new updates create to both the base table and worldwide second index.


To view the provisioned throughput settings for a worldwide secondary index, usage the DescribeTable procedure. Detailed indevelopment about all of the table"s worldwide additional indexes is changed.

Read Capacity Units

Global second indexes assistance ultimately constant reads, each of which consume one fifty percent of a check out capacity unit. This means that a single international second index query deserve to retrieve as much as 2 × 4 KB = 8 KB per read capacity unit.

For worldwide secondary index queries, DynamoDB calculates the provisioned read task in the exact same method as it does for queries versus tables. The just distinction is that the calculation is based upon the sizes of the index entries, fairly than the dimension of the item in the base table. The variety of read capacity devices is the sum of all projected attribute sizes across all of the items went back. The result is then rounded up to the following 4 KB boundary. For more indevelopment around just how DynamoDB calculates provisioned throughput consumption, view Managing Setups on DynamoDB Provisioned Capacity Tables.

The maximum dimension of the outcomes went back by a Query operation is 1 MB. This contains the sizes of all the attribute names and worths across every one of the items reverted.

For example, take into consideration a worldwide second index wbelow each item includes 2,000 bytes of data. Now mean that you Query this index and that the query"s KeyConditionExpression matches eight items. The complete size of the corresponding items is 2,000 bytes × 8 items = 16,000 bytes. This result is then rounded approximately the nearemainder 4 KB boundary. Due to the fact that global secondary index queries are eventually consistent, the total price is 0.5 × (16 KB / 4 KB), or 2 read capacity units.

Write Capacity Units

When an object in a table is included, updated, or deleted, and an international additional index is influenced by this, the international additional index consumes provisioned create capacity systems for the procedure. The full provisioned throughput price for a compose consists of the sum of compose capacity units consumed by creating to the base table and also those consumed by updating the global additional indexes. If a create to a table does not need a worldwide secondary index update, no create capacity is consumed from the index.

For a table create to succeed, the provisioned throughput settings for the table and every one of its worldwide additional indexes must have sufficient create capacity to accommoday the write. Otherwise, the write to the table is throttled.

The price of writing an item to a global additional index counts on a number of factors:


If you compose a brand-new item to the table that defines an indexed attribute, or you update an existing item to specify a previously uncharacterized indexed attribute, one write procedure is compelled to put the item into the index.

If an upday to the table alters the worth of an indexed essential attribute (from A to B), two writes are required, one to delete the previous item from the index and an additional create to put the brand-new item right into the index.

If a things was existing in the index, however a write to the table resulted in the indexed attribute to be deleted, one create is forced to delete the old item estimate from the index.

If an object is not current in the index before or after the item is updated, tbelow is no extra create cost for the index.

If an upday to the table just alters the value of projected qualities in the index essential schema, but does not readjust the value of any type of indexed key attribute, one write is compelled to upday the worths of the projected attributes into the index.


All of these determinants assume that the dimension of each item in the index is less than or equal to the 1 KB item size for calculating compose capacity systems. Larger index entries require added write capacity devices. You deserve to minimize your write expenses by considering which qualities your queries will certainly should rerevolve and also projecting only those qualities into the index.

Storage Considerations for Global Secondary Indexes

When an application writes a things to a table, DynamoDB instantly duplicates the correct subset of qualities to any type of worldwide second indexes in which those features should show up. Your steustatiushistory.org account is charged for storage of the item in the base table and additionally for storage of features in any kind of international second indexes on that table.

The amount of area provided by an index item is the amount of the following:


The dimension in bytes of the base table main key (partition crucial and type key)

The size in bytes of the index crucial attribute

The dimension in bytes of the projected attributes (if any)

100 bytes of overhead per index item




See more: Quick Answer: How To Get Rid Of Sock Tan Lines, How To Get Rid Of A Sock Tan: 7 Simple Ways

To estimate the storage demands for a global additional index, you can estimate the average size of an item in the index and also then multiply by the variety of items in the base table that have actually the international secondary index key attributes.

If a table includes an item wbelow a certain attribute is not characterized, yet that attribute is identified as an index partition vital or sort key, DynamoDB doesn"t write any data for that item to the index.


*
Javascript is disabled or is unobtainable in your internet browser.

To usage the Amazon Web Services Documentation, Javascript need to be allowed. Please refer to your browser"s Assistance pages for instructions.