Introduction to Amazon dynamodb

Source: Internet
Author: User
Tags dynamodb amazon dynamodb
ArticleDirectory
    • Data Model concept-tables, items, and attributes
    • Primary Key-primary key
    • Dynamodb Data Type
Data Model concept-tables, items, and attributes

A dynamodb database consists of tables, data items (items), and attributes (attributes. A database has several tables, a table has several items, and each data item has several attributes.

In a relational database, a tables consists of columns. Each records has the same attributes. However, dynamodb is a nosql database. That is to say, except for the primary key, each item can be customized at will without the concept of columns and is not bound by it. The only requirement is that each item should not exceed 64 KB. This means that the total size of all item names and item values should not exceed 64 KB.

The attribute of each item is a key-value structure. The value part of each attribute can be either single-valued or multi-value ). If it is a combination, the value of this set cannot be repeated.

Let's look at an example. Our online store, in order to save products, has a tables structure like this:

 
Products (ID ,...)

There is a primary key to identify the book, and attributes is used to describe the details of the book, such:

{Id = 101 productname = "book 101 title" ISBN = "111-1111111111" authors = ["author 1 ", "author 2"] Price =-2 dimensions = "8.5x11.0x0.5" pagecount = 500 inpublication = 1 productcategory = "book"} {id = 201 productname = "18-bicycle 201" description = "201 description" bicycletype = "road" brand = "brand-Company A" Price = 100 gender = "M" color = ["red ", "Black"] productcategory = "Bike"} {id = 202 productname = "21-bicycle 202" Description = "202 description" bicycletype = "road" brand = "brand-Company A" Price = 200 gender = "M" color = ["green ", "Black"] productcategory = "Bike "}

Note that the aurthors and bike color attributes of the product book are multi-value. This is a JSON-like structure ). Note that dynamodb does not allow the value of atrributes to be null or an empty string ).

Primary Key-primary key

When creating a table, you need a primary key besides the table name. Dynamodb supports the following two primary keys ):

* Hash-type primary keys:

The primary key is the hash value of an attribute. Dynamodb creates an unordered hash index for the primary key atrributes. In the preceding example, the product has an ID as the primary key. This is the hash attribute (attributes) of the table ).

* Hash and Range Primary keys:

A primary key is a combination of two attributes. The first attribute is hash attributes. The second attribute is range attribute. Dynamodb creates an unordered hash index on the hash attribute and a sorted range index on the range attribute. For example, Amazon maintains some forums. Each forum has many thread topics, and each thread has many replies ). You may design the table like this:

Both the thread and reply tables have hash and Range Primary keys. For the thread table, each forum has several subjects. In this way, forumname can be used as hash atrribute, and subject can be used as range attribute. Note that dynamodb does not support join queries between tables. For example, you must save forumname and subject in the reply table ID. In this way, you can use the parse ID to find the corresponding forum and subject.

Dynamodb Data Type

Dynamodb supports two data types:

1. scalar: Number or string)

2. multi-valued: number set or string set)

StringIt is encoded in binary UTF-8. There is no limit on the size of strings other than the primary key. Of course, it cannot exceed the item size (64 KB ). See limits in Amazon dynamodb.

String comparison is used when you use the scan or query interface to return an ordered result. Strings are compared based on ASCII values.

NumberIs a positive or negative integer or decimal number. The decimal point can be precise to 38 digits after the decimal point. Serialized numbers are transmitted to dynamodb in the string type. However, dynamodb processes them in the same way.

String set and number setNote that duplicate values are not allowed in the set, and the set is unordered.

 

Reference

Http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/DataModel.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.