I have the following table structure. My partitionKey currently are not unique however my sortKey is unique.
I also have a Global Secondary Index where my column Column Units is the partitionKey which is unique.
Will removing the
GSIand making thepartitionKeytoColumn Unitswhich is unique make my queries faster and reduce latency.
Reason, I am asking is occasionally I see a spike in DDB calls to this table.
Current Table Structure
GSI - Column Units
| Column Zone (partitionKey) | Column Units (sortKey) |
|---|---|
| A | unique-1 |
| A | unique-2 |
| B | unique-3 |
CodePudding user response:
Removing or Adding Global Secondary Index has no impact on the performance of the base table. A global secondary index is a separate table under the hood and data from the base table get's replicated to it asynchronously.
If you use the GetItem API to request items, it shouldn't matter if you have a primary key (only partition key) or composite primary key (partition key and sort key).
CodePudding user response:
In your case it is okay to duplicate the partition key as you are using a sort key too, if you only use the partition key with duplicate values you will have issues in dynamoDB partitions the data.
DynamoDB stores and retrieves each item based on the primary key value, which must be unique. Items are distributed across 10-GB storage units.
For tables with composite primary keys, the sort key may be used as a partition boundary. DynamoDB splits partitions by sort key if the collection size grows bigger than 10 GB.
