Exams / DVA-C02 / DynamoDB keys, indexes and consistency / Question 1
DVA-C02 practice question: DynamoDB keys, indexes and consistency (1 of 2)
Development with AWS Services A free question from our original DVA-C02 practice exam. Try it, then open the answer to see why each option is right or wrong.
A DynamoDB table named Orders has OrderId as its partition key and has been in production for a year. A new feature must look up all orders for a given customer email address quickly, without scanning the table. What should the developer do?
Choose one answer.
- AA. Add a local secondary index with CustomerEmail as its partition key.
- BB. Run a Scan with a FilterExpression on CustomerEmail for each lookup.
- CC. Add a global secondary index with CustomerEmail as its partition key.
- DD. Change the table's partition key to CustomerEmail with an UpdateTable call.
Show the answer and explanation
Answer: C
- A. Wrong: An LSI must use the table's partition key and can only be created with the table, so it fits neither need.
- B. Wrong: A scan reads the entire table and filters afterwards. It gets slower and costlier as the table grows.
- C. Right: Correct. A GSI can use any attribute as its key and can be added to an existing table, so the app can Query the index by email.
- D. Wrong: A table's primary key cannot be changed after creation. You would have to create a new table and migrate the data.
Explanation
Global secondary indexes can have a partition key and sort key that differ from the base table and can be created on existing tables. Local secondary indexes share the table's partition key and must be defined when the table is created. Indexes let you replace scans with efficient queries.
Study
Keep practising
Answer questions with a score at the end, or practise just this topic with the explanation after each one. No sign-up needed.