IT

해시 및 범위 기본 키란 무엇입니까?

lottoking 2020. 5. 13. 08:17
반응형

해시 및 범위 기본 키란 무엇입니까?


Range 기본 키가 무엇인지 이해할 수 없습니다.

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key

어떻게 작동합니까?

"해시 속성의 정렬되지 않은 해시 인덱스 및 범위 속성의 정렬 된 범위 인덱스"는 무엇을 의미합니까?


" 해시 및 범위 기본 키 DynamoDB의 단일 행이 모두 이루어진 고유 한 기본 키 가지고"란 해시범위 키를 누릅니다. 예를 들어, 해시 키가 X 이고 범위 키가 Y 인 경우 기본 키는 사실상 XY 입니다. 동일한 해시 키에 대해 여러 범위 키를 가질 수도 있지만 조합은 XZXA같이 고유해야합니다 . 각 테이블 유형에 대한 예제를 사용하십시오.

해시 기본 키 – 기본 키는 해시 속성이라는 하나의 속성으로 구성됩니다. 예를 들어 ProductCatalog 테이블은 ProductID를 기본 키로 가질 수 있습니다. DynamoDB는이 기본 키 속성에 정렬되지 않은 해시 인덱스를 구축합니다.

이것은 모든 행이이 값에서 제외됨을 의미합니다. DynamoDB의 모든 행에는이 속성에 필요한 고유 한 값이 있습니다. 정렬되지 않은 해시 색인은 데이터를 정렬하지 않으며 데이터 저장 방법에 대한 보증을 제공하지 않습니다. ProductID가 X보다 큰 모든 행 가져 오기 와 같은 정렬되지 않은 인덱스에 대해서는 쿼리를 수행 할 수 없습니다 . 해시 키를 기반으로 항목을 작성하고 가져옵니다. 예를 들어, ProductID X가있는 테이블에서 행을 가져 오십시오 . 정렬되지 않은 인덱스에 대해 쿼리를 수행하므로 기본적으로 키-값 조회이며 매우 빠르며 처리량이 거의 없습니다.


해시 및 범위 기본 키 – 기본 키는 두 가지 속성으로 구성됩니다. 첫 번째 특성은 해시 특성이고 두 번째 특성은 범위 특성입니다. 예를 들어, 포럼 스레드 테이블은 기본 키로 ForumName 및 Subject를 가질 수 있습니다. 여기서 ForumName은 해시 속성이고 Subject는 범위 속성입니다. DynamoDB는 해시 속성에 정렬되지 않은 해시 인덱스를 만들고 범위 속성에 정렬 된 범위 인덱스를 만듭니다.

이것은 모든 행의 기본 키가 해시와 범위 키조합 임을 의미합니다 . 해시 및 범위 키가 모두있는 경우 단일 행에서 직접 가져 오기를 수행하거나 정렬 된 범위 인덱스 에 대해 쿼리를 작성할 수 있습니다 . 예를 들어, 범위 키가 Y보다 큰 해시 키 X 또는 그에 영향을주는 다른 쿼리가 있는 테이블에서 모든 행을 가져옵니다 . 인덱싱되지 않은 필드에 대한 스캔 및 쿼리와 비교하여 성능이 우수하고 용량 사용량이 적습니다. 에서 해당 설명서 :

쿼리 결과는 항상 범위 키를 기준으로 정렬됩니다. 범위 키의 데이터 유형이 숫자 인 경우 결과는 숫자 순서로 리턴됩니다. 그렇지 않으면 결과는 ASCII 문자 코드 값 순서로 리턴됩니다. 기본적으로 정렬 순서는 오름차순입니다. 순서를 반대로하려면 ScanIndexForward 매개 변수를 false로 설정하십시오.

내가 이것을 타이핑 할 때 아마 몇 가지를 놓 쳤고 표면 만 긁었습니다. 있습니다 많은DynamoDB의 테이블로 작업 할 때 고려해야 할 측면 (처리량, 일관성, 용량, 기타 인덱스, 키 분배 등). 예제 테이블과 데이터 페이지를 살펴보십시오 .


모든 것이 섞이고 있습니다. 먼저 빌딩 블록은 다음과 같습니다.

  1. 안건
  2. KV 속성.

항목을 행으로, KV 속성을 해당 행의 셀로 생각하십시오.

  1. 기본 키로 항목 (행)을 얻을 수 있습니다.
  2. (HashKey, RangeKeyQuery)를 지정하여 여러 항목 (여러 행)을 가져올 수 있습니다.

PK가 (HashKey, SortKey)로 구성되어 있다고 결정한 경우에만 (2)를 수행 할 수 있습니다.

더 복잡한 것처럼 시각적으로 보았습니다.

+----------------------------------------------------------------------------------+
|Table                                                                             |
|+------------------------------------------------------------------------------+  |
||Item                                                                          |  |
||+-----------+ +-----------+ +-----------+ +-----------+                       |  |
|||primaryKey | |kv attr    | |kv attr ...| |kv attr ...|                       |  |
||+-----------+ +-----------+ +-----------+ +-----------+                       |  |
|+------------------------------------------------------------------------------+  |
|+------------------------------------------------------------------------------+  |
||Item                                                                          |  |
||+-----------+ +-----------+ +-----------+ +-----------+ +-----------+         |  |
|||primaryKey | |kv attr    | |kv attr ...| |kv attr ...| |kv attr ...|         |  |
||+-----------+ +-----------+ +-----------+ +-----------+ +-----------+         |  |
|+------------------------------------------------------------------------------+  |
|                                                                                  |
+----------------------------------------------------------------------------------+

+----------------------------------------------------------------------------------+
|1. Always get item by PrimaryKey                                                  |
|2. PK is (Hash,RangeKey), great get MULTIPLE Items by Hash, filter/sort by range     |
|3. PK is HashKey: just get a SINGLE ITEM by hashKey                               |
|                                                      +--------------------------+|
|                                 +---------------+    |getByPK => getBy(1        ||
|                 +-----------+ +>|(HashKey,Range)|--->|hashKey, > < or startWith ||
|              +->|Composite  |-+ +---------------+    |of rangeKeys)             ||
|              |  +-----------+                        +--------------------------+|
|+-----------+ |                                                                   |
||PrimaryKey |-+                                                                   |
|+-----------+ |                                       +--------------------------+|
|              |  +-----------+   +---------------+    |getByPK => get by specific||
|              +->|HashType   |-->|get one item   |--->|hashKey                   ||
|                 +-----------+   +---------------+    |                          ||
|                                                      +--------------------------+|
+----------------------------------------------------------------------------------+

그래서 위에서 일어나는 일. 다음 관찰 사항을 확인하십시오. 우리가 말했듯이 데이터는 (Table, Item, KVAttribute)에 속합니다. 그런 다음 모든 항목에 기본 키가 있습니다. 이제 기본 키를 작성하는 방법은 데이터에 액세스하는 방법에 의미가 있습니다.

If you decide that your PrimaryKey is simply a hash key then great you can get a single item out of it. If you decide however that your primary key is hashKey + SortKey then you could also do a range query on your primary key because you will get your items by (HashKey + SomeRangeFunction(on range key)). So you can get multiple items with your primary key query.

Note: I did not refer to secondary indexes.


A well-explained answer is already given by @mkobit, but I will add a big picture of the range key and hash key.

In a simple words range + hash key = composite primary key CoreComponents of Dynamodb enter image description here

A primary key is consists of a hash key and an optional range key. Hash key is used to select the DynamoDB partition. Partitions are parts of the table data. Range keys are used to sort the items in the partition, if they exist.

So both have a different purpose and together help to do complex query. In the above example hashkey1 can have multiple n-range. Another example of range and hashkey is game, userA(hashkey) can play Ngame(range)

enter image description here

The Music table described in Tables, Items, and Attributes is an example of a table with a composite primary key (Artist and SongTitle). You can access any item in the Music table directly, if you provide the Artist and SongTitle values for that item.

A composite primary key gives you additional flexibility when querying data. For example, if you provide only the value for Artist, DynamoDB retrieves all of the songs by that artist. To retrieve only a subset of songs by a particular artist, you can provide a value for Artist along with a range of values for SongTitle.

enter image description here

https://www.slideshare.net/InfoQ/amazon-dynamodb-design-patterns-best-practices https://www.slideshare.net/AmazonWebServices/awsome-day-2016-module-4-databases-amazon-dynamodb-and-amazon-rds https://ceyhunozgun.blogspot.com/2017/04/implementing-object-persistence-with-dynamodb.html


@vnr you can retrieve all the sort keys associated with a partition key by just using the query using partion key. No need of scan. The point here is partition key is compulsory in a query . Sort key are used only to get range of data

참고URL : https://stackoverflow.com/questions/27329461/what-is-hash-and-range-primary-key

반응형