Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

For partition key queries on composite keys, what is the cost?

Let’s say we have a composite key : name (partition key) and timestamp (sort key)

If I query name with the latest timestamp, would I bear the cost of all entries inside the partition, or only the latest entry?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you do a Query with Limit=1 and ScanIndexForward=False then you will get the latest value and only pay to read 1 item.

aws dynamodb query \
--table-name my-table \
--key-condition-expression "#pk = :pk" \
--expression-attribute-values '{":pk":{"S":"leeroy"}' \
--expression-attribute-names '{"#pk":"name"}' \
--no-scan-index-forward \
--limit 1

Likewise, if you know the name and timestamp you can do a GetItem and only pay to read 1 item.

aws dynamodb get-item \
--table-name my-table \
--key '{"name": {"S": "leeroy"},"timestamp": {"S": "2023-01-01T20:00:000"}}'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading