Dynamodb-indexes

提供:Dev Guides
移動先:案内検索

DynamoDB-インデックス

DynamoDBは、主キー属性のインデックスを使用してアクセスを改善します。 アプリケーションのアクセスとデータの取得を高速化し、アプリケーションの遅延を減らすことでパフォーマンスの向上をサポートします。

二次インデックス

セカンダリインデックスは、属性サブセットと代替キーを保持します。 インデックスを対象とするクエリまたはスキャン操作で使用します。

その内容には、投影またはコピーする属性が含まれます。 作成時に、インデックスの代替キーと、インデックスに投影する属性を定義します。 次に、DynamoDBは、テーブルから取得したプライマリキー属性を含む、属性のコピーをインデックスに実行します。 これらのタスクを実行した後、テーブルで実行するかのようにクエリ/スキャンを使用するだけです。

DynamoDBは、すべてのセカンダリインデックスを自動的に維持します。 追加や削除などのアイテム操作では、ターゲットテーブルのインデックスが更新されます。

DynamoDBは、2種類のセカンダリインデックスを提供します-

  • グローバルセカンダリインデックス-このインデックスにはパーティションキーとソートキーが含まれますが、これらはソーステーブルとは異なる場合があります。 すべてのテーブルデータとすべてのパーティションにまたがるインデックスのクエリ/スキャン機能により、ラベル「グローバル」を使用します。
  • ローカルセカンダリインデックス-このインデックスはパーティションキーをテーブルと共有しますが、異なるソートキーを使用します。 その「ローカル」な性質は、すべてのパーティションが同一のパーティションキー値を持つテーブルパーティションにスコープされていることに起因します。

使用するインデックスの最適なタイプは、アプリケーションのニーズによって異なります。 次の表に示されている2つの違いを考慮してください-

Quality Global Secondary Index Local Secondary Index
Key Schema It uses a simple or composite primary key. It always uses a composite primary key.
Key Attributes The index partition key and sort key can consist of string, number, or binary table attributes. The partition key of the index is an attribute shared with the table partition key. The sort key can be string, number, or binary table attributes.
Size Limits Per Partition Key Value They carry no size limitations. It imposes a 10GB maximum limit on total size of indexed items associated with a partition key value.
Online Index Operations You can spawn them at table creation, add them to existing tables, or delete existing ones. You must create them at table creation, but cannot delete them or add them to existing tables.
Queries It allows queries covering the entire table, and every partition. They address single partitions through the partition key value provided in the query.
Consistency Queries of these indices only offer the eventually consistent option. Queries of these offer the options of eventually consistent or strongly consistent.
Throughput Cost It includes throughput settings for reads and writes. Queries/scans consume capacity from the index, not the table, which also applies to table write updates. Queries/scans consume table read capacity. Table writes update local indexes, and consume table capacity units.
Projection Queries/scans can only request attributes projected into the index, with no retrievals of table attributes. Queries/scans can request those attributes not projected; furthermore, automatic fetches of them occur.

セカンダリインデックスを使用して複数のテーブルを作成する場合は、順番に実行します。つまり、テーブルを作成し、ACTIVE状態になるのを待ってから、別のテーブルを作成してから再び待機します。 DynamoDBは同時作成を許可しません。

各セカンダリインデックスには特定の仕様が必要です-

  • タイプ-ローカルまたはグローバルを指定します。
  • 名前-テーブルと同じ命名規則を使用します。
  • キースキーマ-トップレベルの文字列、数値、またはバイナリタイプのみが許可され、インデックスタイプが他の要件を決定します。
  • 投影の属性-DynamoDBは自動的に投影し、任意のデータ型を許可します。
  • スループット-グローバルセカンダリインデックスの読み取り/書き込み容量を指定します。

インデックスの制限は、テーブルごとに5つのグローバルと5つのローカルのままです。

*DescribeTable* を使用して、インデックスに関する詳細情報にアクセスできます。 名前、サイズ、アイテム数を返します。

_ -これらの値は6時間ごとに更新されます。_

インデックスデータへのアクセスに使用されるクエリまたはスキャンで、テーブル名とインデックス名、結果に必要な属性、および条件ステートメントを指定します。 DynamoDBは、結果を昇順または降順で返すオプションを提供します。

_ -テーブルを削除すると、すべてのインデックスも削除されます。_