How does DynamoDB Query act when all items are in a single item collection?

Viewed 197

I have dynamodb and I use lambda to query the tables using python, My columns are:

  • product_id,
  • product_name,
  • create_at,

I'd like to be able to sort every column In descending or ascending order. From what I have read, I came to the conclusion that I need to create the first column as Partition, and in every record, I have the same value, let's say "dummy". Moreover, I need to create the create_at as a sort key and; for the other columns I need to create a local secondary index for each of them.Then when I sort, I can do that

    response = table.query(
        KeyConditionExpression=Key('dummy_col').eq('dummy'),
        IndexName=product_name_index
        ScanIndexForward=True,
    )

what I don't understand is that: will my query Go through all the records like scanning, because of my dummy value in every record?

1 Answers

If you require all these access patterns, that's one way to design your table. It has some limitations though - you won't be able to have more than 10GB of data in total, because when you use Local Secondary Indexes, that limits the item collection (all items with the same PK) size to 10GB.

Each query reads and returns up to 1MB of data (docs), afterwards you will get a token that you can use to request the next 1 MB (LastEvaluatedKey)in a new query (ExclusiveStartKey). You can also use the Limit parameter to limit how many items will be read and returned per Query. If you read the whole table based on that, you'll effectively have scanned it.

By filtering based on the sort key you can also define where it starts to read, so you don't have to read everything all the time.

Related