1

I know DynamoDB scan doesn't guarantee ordering of items across the board but i wonder if atleast items with the same partition key still get returned in order?

For example would the following events atleast be returned in order?

pk:customer-event / sk:1
pk:customer-event / sk:2
pk:customer-event / sk:3

I have tested with a small dataset and it does seem to have the behaviour i'm after but i don't want to assume behaviour.

jarmod
  • 71,565
  • 16
  • 115
  • 122
  • 1
    For more, see [Key Concepts](https://www.dynamodbguide.com/key-concepts/). This obviously only relates to tables with composite primary keys (that have both pk and sk): the sort key (sk) is used to sort items with the same partition key (pk). – jarmod May 28 '23 at 15:40

1 Answers1

3

Yes, that’s how scans work. The PKs are in the order of their hashed values, then SKs in the order of their true values.

hunterhacker
  • 6,378
  • 1
  • 14
  • 11
  • Right. This is exactly why the second key component is called the "sort key" - exactly as its name suggests, it is used to sort the items in the partition. This sorted-partition data model is shared by DynamoDB, Cassandra and ScyllaDB (see https://stackoverflow.com/questions/60798118/how-do-you-call-the-data-model-of-dynamodb-and-cassandra). – Nadav Har'El May 28 '23 at 12:39
  • Thanks, yeah I understand these semantics. My question was more just to get confirmation as i wasn't sure if for whatever reason DynamoDB scan done something under the hood which ignored the expected semantics. For peace of mind really. – Declan Price May 28 '23 at 18:29