Each item in DynamoDB table consists of:

  • hash key
  • range key (on which results are ranged)
  • attributes

Fast query lookups are possible only on:

  • hash key or hash + range key together
  • but not on attributes

To enable fast query lookups on attributes we can create Global Secondary Index (GSI)

For example assume we have a table with game scores:

Game scores indexing

Target: Count total score by all games with one GameTitle:

As simple scan by GameTitle will be slow (because it is not hash key), we can create index GameTitleIndex which will give fast TopScores for certain GameTitle:

Secondary index

Results will be ranged(sorted) by range key.

Based on https://www.youtube.com/watch?v=qNhiFdDAWJU