Thursday, 15 March 2012

Uniqueness in DynamoDB secondary index -



Uniqueness in DynamoDB secondary index -

question:

dynamodb tables primary key composite hash-range key unique. extend secondary indices too?

example:

i have comments dynamodb table post_id primary key , comment_id range key. additionally there's local secondary index date-user_id range key.

each entry comment user has left on post. purpose of secondary index count how many unique users left comment on post on specific day.

entry 1: post_id: 1 comment_id: 1 date-user_id: 2014_06_24-1

entry 2: post_id: 1 comment_id: 2 date-user_id: 2014_06_24-1

entry 3: post_id: 1 comment_id: 3 date-user_id: 2014_06_24-2

when query specifying secondary index, , pass in status of post_id equals 1 , date-user_id equals 2014_06_24-1, i'm getting count of 2 , i'm expecting count of 1.

why secondary index have 2 entries same primary key/range key.

each item in local secondary index (lsi) has 1:1 relationship corresponding item in table. in illustration above, while entry 1 , entry 2 in lsi have same range key value, item in table point different. hence index keys ( hash or hash+range) not unique.

global secondary index (gsi) similar lsi in aspect. every gsi item contains table hash , range keys (of corresponding item). more details available @ http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/gsi.html#gsi.projections

amazon-dynamodb

No comments:

Post a Comment