Create secodary indexes in DynamoDB example
Each item in DynamoDB table consists of:
hash
keyrange
key (on which results are ranged)- attributes
Fast query lookups are possible only on:
hash
key orhash + 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:
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
:
Results will be ranged(sorted) by range key.