What is Hash and Range Primary Key?

前端 未结 4 2024
北海茫月
北海茫月 2020-12-12 08:51

I am not able to understand what Range / primary key is here in the docs on Working with Tables and Data in DynamoDB

How does it work?

What do they mean by &qu

4条回答
  •  萌比男神i
    2020-12-12 09:26

    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

    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)

    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.

    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

提交回复
热议问题