[英]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: 根据您的应用程序,这里有两种方法:
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. StaffID
and Name
, create a global secondary index for the table using the Name
field. StaffID
和Name
有效查询,请使用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.