The three generic attributes will be used to support two indexes: the main table index which uses pk as the partition 和 sk as the sort key, 和 a global secondary index which uses sk as the partition 和 data as the sort.
Each Customer, each Order, each Shipper record gets an item in our new table. In each of our cases, we’ll make the pk attribute correspond to the primary key of the relational record. The sk 和 data attributes, though, we’ll vary based on the kinds of queries we need to write. See the breakdown below:
The Order, Product, 和 Supplier records use a static value as the partition key for GS1. This lets us look up 所有 items of a particular type (such as 所有 orders that match a date range) without resorting to an expensive scan operation. You can think of this as a workaround for the loss of our precious attribute keys: we’re using a value as a key instead.
我们使用了一个称为 层次排序键 as the data field for the Customer 和 Supplier records. By combining 所有 the address details into one field, we can get country, region 和 city lookups for the price of a single GSI.
In the 北风 dataset, the many-to-many relationship we’ll focus on is expressed in the OrderDetails join table. An order can have many products, one product can appear in many orders, 和 the attributes of that relationship are expressed in OrderDetails. We’ll model this relationship by placing the OrderDetails records in the Order partition of our table.