DynamoDB series--several core concepts

DynamoDB is a NoSql database launched by Amazon. After Amazon went to Oracle database, it also began to use its own DynamoDB. So what are the core concepts of DynamoDB? Let's talk today

Before talking about the concept, let's take a look at a screenshot of a DynamoDB table. Is it similar to a table in a relational database like Mysql?

img.png

DynamoDB Core Concepts

  1. tables, items, and attributes;
  2. primary keys;
  3. secondary indexes;
  4. read and write capacity.

Tables、Items、Attributes

Tables, Items, and Attributes are the core components of DynamoDB.

Tables: Tables store a set of data records, such as the Users table to store user information, similar to tables in relational databases or collections in MongoDB.

Items: row, a single data record in a table. Similar to a row in a relational database or a document in MongoDB.

Attributes: attributes, fields in each item. Similar to a column in a relational database or a field in MongoDB.

Primary keys

Primary keys: The primary key is used to uniquely identify each row of data (Item) in the table. It is similar to the primary key in a relational database such as mysql. The primary key of DynamoDB must be set when creating a table. There are two primary keys in DynamoDB Types: simple primary key and composite primary key.

As shown in the figure below: only the Partition key used for partitioning is set as a simple primary key, and when the Partition key for partitioning and the Sort key for sorting are set at the same time, it is a composite primary key. Regardless of whether a simple primary key or a composite primary key is used, an Item in a DynamoDB table can be uniquely identified.

img.png

Secondary indexes

Secondary Indexes: secondary index

Friends who have used mysql relational database must know that the primary key can uniquely identify a record in Mysql, but sometimes we not only rely on the primary key for query, for example, in the order table, in addition to querying through the primary key order id , we also want to query the order through the user id; similarly, in DynamoDB, indexes other than the primary key are called secondary indexes, and there are two types of secondary indexes: local secondary indexes and global secondary indexes.
The following is a screenshot of the table index:

img.png

local secondary indexes

Local secondary indexes use the same partition key (Partition key) as the underlying table, but use a different sort key (Sort key). Taking the Order table as an example, suppose you want to quickly access customer orders in descending order of customer order amount. You can add a local secondary index whose partition key is CustomerId and sort key is Amount, so that customers' orders can be efficiently queried by amount.

global secondary indexes

Global secondary indexes allow queries to be performed on attributes that are not part of the table's primary key. Note that global secondary index read and write capacity settings are separate from table settings, and they incur additional costs.

Read and Write Capacity

Read and Write Capacity: read and write capacity

When using MySQL, Postgres, or MongoDB database, when we need multiple servers, we need to set cpu, memory, hard disk capacity and other information, but when using DynamoDB, we don’t need to pay attention to these, only need to configure the read and write capacity unit. These units allow a given number of operations per second. At the same time, DynamoDB can also automatically expand the read and write capacity units. It is convenient to dynamically expand application services during peak hours.

Guess you like

Origin blog.csdn.net/m0_54369189/article/details/126545130