Wuubb
Wuubb

Reputation: 71

Querying main table vs scanning secondary index in DynamoDB

If I have a DynamoDB table with pk and sk where pk is such that I can query the table for a given pk and get all items in a given category, how does this differ from scanning a sparse secondary index that contains only items from said category? I know GSI read/write units are separate from the main table, but I'm wondering if there is a latency or other benefit to be had from doing one over the other.

Upvotes: 1

Views: 1047

Answers (1)

jellycsc
jellycsc

Reputation: 12259

AFAIK, in theory, there shouldn't be any performance difference between them. First of all, the primary table and GSI both use the same underlying storage nodes, so the IO performance should be the same. Secondly, no matter you query the primary table or scan the sparse GSI, the partition key of the records you are retrieving is the same, which means all those records reside in the same partition (not split in shards).

Some benefits I can think of to do queries in the primary table:

  1. Save RCU, WCU and storage cost of the GSI
  2. You have the ability to do consistent reads

Upvotes: 1

Related Questions