I have a DynamoDB table that stores executions of some programs, this is what it looks like:
Partition Key | Sort Key | StartDate | ... |
---|---|---|---|
program-name | execution-id (uuid) | YYYY-MM-DD HH:mm:ss | ... |
I have two query scenarios for this table:
- Query by program name and execution id (easy)
- Query by start date range, for example: all executions from
2021-05-15 00:00:00
to2021-07-15 23:59:59
What is the correct way to perform the second query?
I understand I need to create a GSI to do that, but how should this GSI look like?
I was thinking about splitting the StartDate
attribute into two, like this:
Partition Key | Sort Key | StartMonthYear | StartDayTime | ... |
---|---|---|---|---|
program-name | execution-id (uuid) | YYYY-MM | DD HH:mm:ss | ... |
So I can define a GSI using the StartMonthYear
as the partition key and the StartDayTime
as the sort key.
The only problem with this approach is that I would have to write some extra logic in my application to identify all the partitions I would need to query in the requested range. For example:
If the range is: 2021-05-15 00:00:00
to 2021-07-15 23:59:59
I would need to query 2021-05
, 2021-06
and 2021-07
partitions with the respective day/time restrictions (only the first and last partition is this example).
Is this the correct way of doing this or am I totally wrong?