0

I want to create a DynamoDB table with a GSI. For this GSI, currently I need only PartitionKey because I want to query by only one attribute. But in future I may need to query by other attributes. So, I am thinking of adding a SortKey just in case if I need to query by another attribute in future. For now it can be empty or can have the same value as PK.

In GSI, are there any drawbacks of adding SortKey, if I am not planning to use it in foreseeable future?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
CharithJ
  • 46,289
  • 20
  • 116
  • 131
  • If you don't know in advance which additional attribute you will want as a sort key, can you even create a composite-key GSI? – jarmod May 11 '22 at 12:08
  • @jarmod: Yes I'll be using the same value as in PK for SK to start with. – CharithJ May 11 '22 at 12:11
  • Then I'd imagine the only downside is the cost of the extra storage associated with the SK. – jarmod May 11 '22 at 12:19

1 Answers1

2

The (probably very) minor downsides of this approach are:

  1. marginally higher storage costs and
  2. added developer overhead of having to provide the (currently meaningless) index SK as part of the primary Key in CRUD operations.
fedonev
  • 20,327
  • 2
  • 25
  • 34
  • Does it have costs for storage? I'd thought it's only for RCU and WCU? – CharithJ May 11 '22 at 12:47
  • 1
    Yes. Docs: DynamoDB charges for reading, writing, and storing data in your DynamoDB tables, along with any optional features you choose to enable. [DynamoDB measures the size of your billable data by adding the raw byte size of your data plus a per-item storage overhead that depends on the features you have enabled.](https://aws.amazon.com/dynamodb/pricing/on-demand/#.E2.80.A2_Data_storage) – fedonev May 11 '22 at 13:21