如何在 AWS(DynamoDB 或 SQL)中索引两列数据库以提高性能
How to index a two column database in AWS (DynamoDB or SQL) for preformance
我想要一种有效的方法来存储 ItemID 和 AttributeID,以便在 DynamoDb 中进行查询。
有几千个唯一的 ItemID 和 300 个唯一的 AttributeID。
每个 ItemID 通常与 20-100 个 AttributeID 相关联。
每个 AttributeID 与 20,000-40,000 个 ItemID 相关联
随着时间的推移,将会添加更多的 AttributeID。
我希望能够通过查询找到:
- Return 我是与给定 ItemID 关联的 AttributeID
- 查找与给定 AttributeID 关联的 ItemID
我最初的解决方案是
DynamoDB:有一个 table,其中一个 ItemID 与一个 AttributeID 相匹配。主键将是 Hash 和 Rage,其中 Hash = ItemID 和 Range = AttributeID。有一个全局二级索引,Hash 和 Range,其中 Hash= AttributeID 和 Range = ItemID.
与上面相同,但使用 SQL,尽管这将导致大约 900 万个条目,这会降低性能,尤其是当我添加更多 AttributeID 时。
我的解决方案是否可行,或者更好的方法是什么?按照我建议的方式,SQL 和 DynamoDB 版本(由于底层 table 实现)之间的性能会有任何差异吗?
你应该
- table
Item
索引在 ItemID
- table
Atribute
索引在 AtributeID
- table
Item Atribute
有两个字段 ItemID, AtributeID
有两个字段的复合索引。
而 900 万对于数据库来说不算什么。使用索引,您将在几毫秒内找到每个项目的属性。
我想要一种有效的方法来存储 ItemID 和 AttributeID,以便在 DynamoDb 中进行查询。
有几千个唯一的 ItemID 和 300 个唯一的 AttributeID。 每个 ItemID 通常与 20-100 个 AttributeID 相关联。 每个 AttributeID 与 20,000-40,000 个 ItemID 相关联 随着时间的推移,将会添加更多的 AttributeID。
我希望能够通过查询找到:
- Return 我是与给定 ItemID 关联的 AttributeID
- 查找与给定 AttributeID 关联的 ItemID
我最初的解决方案是
DynamoDB:有一个 table,其中一个 ItemID 与一个 AttributeID 相匹配。主键将是 Hash 和 Rage,其中 Hash = ItemID 和 Range = AttributeID。有一个全局二级索引,Hash 和 Range,其中 Hash= AttributeID 和 Range = ItemID.
与上面相同,但使用 SQL,尽管这将导致大约 900 万个条目,这会降低性能,尤其是当我添加更多 AttributeID 时。
我的解决方案是否可行,或者更好的方法是什么?按照我建议的方式,SQL 和 DynamoDB 版本(由于底层 table 实现)之间的性能会有任何差异吗?
你应该
- table
Item
索引在ItemID
- table
Atribute
索引在AtributeID
- table
Item Atribute
有两个字段ItemID, AtributeID
有两个字段的复合索引。
而 900 万对于数据库来说不算什么。使用索引,您将在几毫秒内找到每个项目的属性。