简体   繁体   English

DynamoDB无需使用主键即可进行查询的最佳解决方案

[英]DynamoDB best solution to making queries without using the primary key

I have a table in DyamoDB similar to this: 我在DyamoDB中有一个与此表类似的表:

StaffID, Name,          Email,              Office
1514923  Winston Smith, SmithW@company.com, 101

It only has around 100 rows. 它只有大约100行。

I'm experimenting with Amazon's Alexa and the possibility of using it for voice-based queries such as 我正在尝试使用Amazon的Alexa,并可能将其用于基于语音的查询,例如

'Where is Winston Smith?' “温斯顿·史密斯在哪里?”

The problem is that when using an Alexa function to pull results from the table, it would never be through the primary key StaffID - because you wouldn't have users asking: 问题在于,当使用Alexa函数从表中提取结果时,永远不会通过主键StaffID -因为您不会让用户问:

'Where is 1514923?' 1514923在哪里?

From what I've read, querying the non-primary key values is extremely slow... Is there a suitable solution to this when using Python with DynamoDB? 根据我的阅读,查询非主键值的速度非常慢...将Python与DynamoDB结合使用时,是否有合适的解决方案?

I know that with only 100 rows it is negligible - but I'd like to do things in the correct, industry standard way. 我知道只有100行可以忽略不计-但是我想以正确的行业标准方式来做事情。 Or is the best solution with cases like this, to simply scan the tables - splitting them up for different user groups when they get too large? 还是这种情况的最佳解决方案,就是简单地扫描表-在表太大时将它们拆分为不同的用户组?

There are two approaches here, depending on your application: 根据您的应用程序,这里有两种方法:

  1. If you only ever want to query this table via the Name field, then change the table so that it has a partition key of Name instead of StaffID . 如果您只想通过“ Name字段查询该表,请更改该表,使其具有Name的分区键而不是StaffID DynamoDB isn't SQL - there's no need to have everything keyed on an ID field unless you actually use it. DynamoDB不是SQL-除非您实际使用它,否则无需将所有内容都键入ID字段。 (Note you can't actually "change" the partition key on an existing DynamoDB table - you'll have to rebuild the table). (请注意,您实际上无法“更改”现有DynamoDB表上的分区键-您必须重建表)。
  2. If you want to query efficiently via both StaffID and Name , create a global secondary index for the table using the Name field. 如果要通过StaffIDName有效查询,请使用Name字段为表创建一个全局二级索引 Be aware that global secondary indexes need both their own provisioned throughput and storage, both of which of course equal money. 请注意,全局二级索引既需要它们自己的预配置吞吐量,又需要存储,这两者当然是相等的。

Minor aside: this is nothing to do with the fact you're using the Python interface, it applies to all DynamoDB access. 除了一点点:这与您使用Python接口无关,它适用于所有DynamoDB访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在不使用主分区键的情况下查询 DynamoDB 中的所有数据 - Query all data in DynamoDB without using primary partition key 是否在DynamoDB中不传递主键的情况下相当于选择查询? - Equivalent of select query without passing primary key in DynamoDB? DynamoDB 复合主键在系统内移动的最佳实践(分区键和排序键) - Best practice for DynamoDB composite primary key travelling inside the system (partition key and sort key) Python - 如何使用主键和排序键在 GSI 上查询 DynamoDB - Python - How to query DynamoDB on GSI using primary and sort key 检查dynamodb中是否存在主键 - Checking if primary key is existing in dynamodb or not 不使用 Key 属性的 DynamoDB 更新操作 - DynamoDB Update operation without using the Key attribute 在 DRF 中发送文档主键 ID 或发送带有包含 URL 的文档名称的 ID 的最佳解决方案是哪个? - Which is the best solution in DRF sending an ID of primary key of documents or sending ID with the name of document containing the URL? 来自外键的 Django 复合主键的最佳解决方案 - best solution for Django Composite primary-key from foreign-keys DynamoDB AutoIncrement 主键 Python 烧瓶 - DynamoDB AutoIncrement Primary key Python flask DynamoDB - 如何指定不是主键的唯一字段? - DynamoDB - How to specify UNIQUE field that is not a PRIMARY key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM