Dynamo DB概念(Dynamo DB Concepts)

编程入门 行业动态 更新时间:2024-10-27 15:25:50
Dynamo DB概念(Dynamo DB Concepts)

我知道我要问的一些问题会非常愚蠢,但我是Dynamo Db的新手,我对它有很多困惑。

我的问题是:

通过这篇文章了解哈希和范围键的概念后什么是哈希和范围主键? 我想可以创建一个Range键,它不是主键的一部分。 假设我想定义一个表Orders {**Id**,Date,Name....}其中Id作为哈希键,日期作为范围键,日期不作为主键的一部分。

是否可以仅使用哈希键或范围键查询包含主键的表作为哈希和范围键? 就像在表中orders {**ID,Date**,Address,Quantity....}我说我已将主键定义为Hash和Range Key, ID为Hash Key, Date为Range键。 我们可以使用ID或Date查询表,但不能同时使用两者吗?

在创建本地二级指数和全球二级指数时,预测属性的概念是什么?

I know some of the questions I am going to be asked will be so silly, but I am new to Dynamo Db and I have a lot of confusion about it.

My questions are :

After going through concept of Hash and Range key through this post What is Hash and Range Primary Key? I am thinking that is it possible to create a Range key which is not a part of Primary key. Suppose I want to define a Table Orders {**Id**,Date,Name....} with Id as a Hash Key and Date as a Range Key and Date not as a part of Primary Key.

Is it possible to query a Table consisting Primary key as Hash and Range Key with only Hash key or Range key ? Like In Table orders {**ID,Date**,Address,Quantity....} say I have defined primary key as Hash and Range Key with ID as Hash Key and Date as Range key. Can we query on table using only ID or Date but not both ?

What is the concept of projected attributes while creating a Local Secondary Index and Global Secondary Index ?

最满意答案

范围键是主键的一部分。 现在,Range键可能是基表模式或索引(LSI,GSI)的一部分,但它始终是主键的一部分,并且始终伴随着Hash键。 创建表后,无法更改其架构。 您只能对哈希+范围表中特定哈希键的范围键执行查询。 因此,要在给定特定Range键的情况下对Hash键启用查询,您需要在该表中创建一个基本上反转基表模式的GSI。 GSI的Hash密钥是基表的Range密钥,GSI的Range密钥是基表的哈希密钥。 然后,您可以使用与已经用于基表的查询API相同的查询GSI。 例如,假设您有一个具有Hash = owner和Range = BookISBN的Library表。 您可以对属于所有者= Alex的所有图书ISBN或一系列ISBN进行查询,但要查找属于Michelle的图书ISBN,您必须执行不同的查询调用。 现在,使用此架构,很难找到ISBN = 123412341234的图书所有者。 实际上,您必须扫描整个表格以查找ISBN = 123412341234的书籍的所有所有者。 如果您使用Hash = ISBN和Range = owner将名为ISBNIndex的GSI添加到Library表中,则可以使用ISBNIndex GSI上的Query调用来查找ISBN = 123412341234的书籍的所有所有者。 通过投影属性,您可以选择要包含在索引中的项目中的属性。 索引可以通过使用备用模式来加速数据检索。 请参阅GSI和LSI的文档。 基表的主键始终包含在索引投影中。 如果选择KEYS_ONLY,则索引中的项目将仅包括基表和索引主键。 如果选择INCLUDE,则除了基表和索引主键之外,您在NonKeyAttributes中指定的属性将包含在索引中。 如果选择ALL,则所有项属性都将投影到索引中。 有关更多信息,请参阅CreateTable文档 。 A Range key is part of a primary key. Now, a Range key might be part of the schema of the base table or an index (LSI, GSI) but it will always be part of a primary key, and will always be accompanied by a Hash key. Once you create a table, you cannot change its schema. You can only do Query on the Range key for a particular Hash key in a Hash+Range table. Therefore, to enable Queries on the Hash key given a particular Range key, you would need to create a GSI in that table that basically reverses the schema of your base table. The Hash key of the GSI would be the Range key of the base table, and the Range key of the GSI would be the hash key of the base table. Then, you can Query the GSI using the same Query API as you can already use for the base table. For example, say you have a Library table that has Hash=owner and Range=BookISBN. You can do a Query for all the book ISBNs that belong to the owner=Alex, or for a range of ISBN, but to find the book ISBNs that belong to Michelle, you would have to do a different Query call. Now, with this schema, it is difficult to find the owners of the book with ISBN=123412341234. In fact, you would have to Scan the entire table to find all the owners of the book with ISBN=123412341234. If you add a GSI called ISBNIndex to your Library table with Hash=ISBN and Range=owner, then you can use a Query call on the ISBNIndex GSI to find all the owners of a book with ISBN=123412341234. Projected attributes allow you to select the attributes you want to include in items in your indexes. Indexes can speed up data retrieval by use of alternate schemas. See the documentation for GSI and LSI. The primary keys of the base table are always included in index projections. If you select KEYS_ONLY, items in the index will only include base table and index primary keys. If you select INCLUDE, the attributes you specify in NonKeyAttributes will be included in the index in addition to the base table and index primary keys. If you select ALL, all the item attributes will be projected into the index. For more information, see the CreateTable documentation.

更多推荐

本文发布于:2023-07-22 06:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:概念   Dynamo   DB   Concepts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!