McGar
McGar

Reputation: 205

Make a dynamodb attribute as partition key of one index and as sort key of another index

Is that possible to make an attribute as partition key of one index and as sort key of another index?

For example, I have a table named Events with attributes user, status, created_at.

Can I create both of below GSIs
GSI user_status [user as partition, status as sort]
GSI status_created_at [status as partition, created_at as sort]

Upvotes: 0

Views: 200

Answers (1)

Mike Dinescu
Mike Dinescu

Reputation: 55760

That is pretty much the idea with GSIs. In short: the answer is yes.

Be cautious, though, of creating GSIs where you have massive cardinality on a small set of partition keys, such as the second GSI example where you partition on status. Presumably there are only a handful of status values in total but for each status, the cardinality (number of items with the same status) might be very large. The reason this can be a problem is that GSIs, like tables, are subject to read and write capacity limits which apply per partition. As your table scales, having low distribution accross partitions with very high cardinality could result in poor performance.

Upvotes: 0

Related Questions