We really struggled with implementing adhoc queries/search. For e.g:- select * from employees where name = X and city = Y.
Any improvements in DynamoDB that make it easier to implement such queries?
We really struggled with implementing adhoc queries/search. For e.g:- select * from employees where name = X and city = Y.
Any improvements in DynamoDB that make it easier to implement such queries?
Dynamo is primarily designed for high volume storage/querying on well understood data sets with a few query patterns. If you want to be able to query information on employees based on their name and city you'll need to build another index keyed on name and city (in practice Dynamo makes that reasonably simple by adding a secondary index).
This is often easier said than done, but it can be far less expensive and more performant than adding an index for each search.
If what you are trying to do looks more like "Give me all the customers that live in Cuba and have spent more than $10 and have green eyes", Dynamo isn't for you. You can query that way but after you put all the work in to get it up and running, you'd probably be better off with Postgres.
Data should be stored in the fashion you wish for it to be read, and storing the same data in more than one configuration is acceptable.
Good resource: https://docs.aws.amazon.com/amazondynamodb/latest/developerg...
However, so long as you add a global secondary index (GSI) with name, city as the key, you can certainly do such things. But be aware for large-scale solutions:
1. There's a limit of 20 GSIs per table. You can increase with a call to AWS support.
2. GSIs are latently updated; read-after write is not guaranteed, and there is no "consistent read" option on a GSI like there is with tables.
3. WCUs on GSIs should match (or surpass) the WCUs on the original table, else throughput limit exceeded exceptions will occur. So, 3 GSIs on a table means you pay 4x+ in WCU costs.
4. The keys of the GSI should be evenly distributed, just like the PK on a main table. If not, there is additional opportunity for hot partitions on write.
Ref: https://aws.amazon.com/premiumsupport/knowledge-center/dynam...
If you want to search by parameters that aren't keys then you need to store your data that way. Most of these systems have secondary indexes now, and that's basically what they do for you automatically in the backend, storing another copy of your records using a different key.
If you need adhoc relational queries then you should use a relational database.
Not that I recommend it, but by using space-filling curves, one could to index multiple dimensions onto DynamoDB's bi-dimensional (hash-key, range-key) primary-index: https://aws.amazon.com/blogs/database/z-order-indexing-for-m... and https://web.archive.org/web/20220120151929/https://citeseerx...
https://docs.aws.amazon.com/amazondynamodb/latest/developerg...
I haven't used DynamoDB in a couple of years, so I'd be curious to know how querying compares if anyone can share some light that has used both Cosmos and Dynamo recently.