简体   繁体   中英

DynamoDB best solution to making queries without using the primary key

I have a table in DyamoDB similar to this:

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

It only has around 100 rows.

I'm experimenting with Amazon's Alexa and the possibility of using it for voice-based queries such as

'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:

'Where is 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?

I know that with only 100 rows it is negligible - but I'd like to do things in the correct, industry standard way. 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 . DynamoDB isn't SQL - there's no need to have everything keyed on an ID field unless you actually use it. (Note you can't actually "change" the partition key on an existing DynamoDB table - you'll have to rebuild the table).
  2. If you want to query efficiently via both StaffID and Name , create a global secondary index for the table using the Name field. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM