How to Efficiently Filter DynamoDB Records by Non-Key Attribute?

A developer is working on an app for a company that uses an Amazon DynamoDB table named Orders to store customer orders. The table uses OrderID as the partition key and there is no sort key. The table contains more than 100,000 records. The developer needs to add a functionality that will retrieve all Orders records that contain an OrderSource attribute with the MobileApp value. Which solution will improve the user experience in the MOST efficient way?

  1. Perform a Scan operation on the Orders table. Provide a QueryFilter condition to filter to only the items where the OrderSource attribute is equal to the MobileApp value.
  2. Create a local secondary index (LSI) with OrderSource as the partition key. Perform a Query operation by using MobileApp as the key.
  3. Create a global secondary index (GSI) with OrderSource as the sort key. Perform a Query operation by using MobileApp as the key.
  4. Create a global secondary index (GSI) with OrderSource as the partition key. Perform a Query operation by using MobileApp as the key. Source Reference Answer

Community Votes

D
83%
C
17%

83% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

Tests efficient querying of non-key attributes via GSIs, with the common trap being confusion between partition and sort key roles in index design.

This scenario evaluates optimal data modeling for filtering non-partition-key attributes using Global Secondary Indexes, with strong community consensus favoring partition-based queries over scans or sort-key-only designs.

Option C is frequently chosen because candidates misunderstand how DynamoDB indexes work, incorrectly assuming that placing the filter attribute as a sort key alone enables efficient partition-level lookups without specifying a partition key value.

Community Discussion (3 comments)

Alagong 👍 5 Selected: D
Answer : D
aws_god 👍 1 Selected: C
You should add the OrderSource as the sort key, only the OrderID is unique should be set as the partition key to give the best performance
Skip 👍 1
Going for B, feel free to comment. I think these comments sections help me a lot!

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Creating a Global Secondary Index (GSI) with OrderSource as the partition key enables direct, highly efficient Query operations. Since the table contains over 100,000 records, a partition-based lookup guarantees logarithmic time complexity and minimal read capacity consumption. This approach isolates the target items to a single partition, delivering consistent sub-millisecond latency that significantly enhances user experience. The AWS documentation explicitly recommends this pattern for accessing data through alternative access paths.

Why the Other Options Are Wrong

Option A triggers a full table Scan, which reads every item regardless of the filter condition, causing excessive latency and high costs. Option B proposes a Local Secondary Index (LSI), but LSIs must share the base table’s partition key (OrderID), making it impossible to use OrderSource as the primary lookup attribute. Option C places OrderSource as a sort key, but a Query operation still requires a valid partition key value to locate data, rendering it ineffective for direct attribute-based filtering. These alternatives fail to provide the deterministic routing necessary for scalable application performance.

Community Comment Notes

Candidate discussions highlight confusion regarding index key placement, with some users incorrectly advocating for sort-key-only configurations due to perceived uniqueness benefits. As noted in the top-voted comments, candidates who selected option C misunderstood how DynamoDB resolves secondary index lookups without a partition key qualifier. Reviewers consistently emphasize that exam scenarios prioritize predictable read patterns over theoretical indexing flexibility. Aligning your mental model with AWS-recommended access patterns will prevent similar pitfalls.

Official Reference

Exam Strategy

When designing for specific access patterns, always map your most frequent query filters directly to a GSI partition key rather than relying on sort keys or full-table scans. Prioritize operations that allow deterministic routing to a single partition to ensure consistent sub-millisecond latency.

Related Analysis

Practice All DVA-C02 Questions

Access 100 questions with complete answers and detailed explanations.

View Full DVA-C02 Practice Test →

← Back to DVA-C02 Study Guide