The ExamScores DynamoDB table uses student_id as the partition key and subject_name as the sort key, with top_score as an attribute. The app needs to quickly return the student_id of the top scorer for each subject. Which change will speed up these queries?
Choose an answer
Tap an option to check your answer.
Correct answer: Create a global secondary index (GSI) with subject_name as the partition key and top_score as the sort key..
Why this is the answer
The correct answer is to create a global secondary index (GSI) with subjectname as the partition key and topscore as the sort key. This GSI allows you to query by subjectname and then efficiently sort by topscore in descending order to find the top scorer for each subject. A GSI is necessary because the query pattern (finding top scores per subject) does not align with the base table's primary key (studentid as partition key). Local secondary indexes (LSIs) must share the same partition key as the base table, so an LSI with subjectname or topscore as the partition key is not possible. An LSI with studentid as the partition key and topscore as the sort key would only help find top scores for a specific student, not across all students for a given subject. A GSI with subjectname as the partition key and studentid as the sort key would allow querying by subject but wouldn't efficiently sort by topscore.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed