0
0
DynamoDBquery~20 mins

Many-to-many with GSI overloading in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GSI Many-to-Many Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Query to find all orders for a given customer using GSI overloading

Given a DynamoDB table with a many-to-many relationship between Customers and Orders using a Global Secondary Index (GSI) that overloads the partition key to store both customer and order data, which query will return all orders for customer with ID C123?

DynamoDB
Table: Orders
Partition Key: PK
Sort Key: SK
GSI1 Partition Key: GSI1PK
GSI1 Sort Key: GSI1SK

Data example:
PK = 'CUSTOMER#C123', SK = 'PROFILE'
PK = 'ORDER#O456', SK = 'DETAILS'
GSI1PK = 'CUSTOMER#C123', GSI1SK = 'ORDER#O456'

Query options:
AScan main table filtering PK = 'CUSTOMER#C123' and SK begins_with 'ORDER#'
BQuery GSI1 with KeyConditionExpression: GSI1PK = 'CUSTOMER#C123' and begins_with(GSI1SK, 'ORDER#')
CQuery main table with KeyConditionExpression: PK = 'CUSTOMER#C123' and SK begins_with 'ORDER#'
DQuery GSI1 with KeyConditionExpression: GSI1PK = 'ORDER#O456' and GSI1SK begins_with 'CUSTOMER#'
Attempts:
2 left
💡 Hint

Remember that GSI1 is designed to link customers to their orders by overloading the partition key.

🧠 Conceptual
intermediate
1:30remaining
Understanding GSI overloading for many-to-many relationships

In a many-to-many relationship modeled in DynamoDB using GSI overloading, what is the main reason for overloading the GSI partition key with different entity prefixes?

ATo automatically replicate data across regions
BTo reduce the size of the main table by storing data only in the GSI
CTo enforce uniqueness of items across different tables
DTo enable querying multiple entity types using the same GSI by distinguishing them with prefixes
Attempts:
2 left
💡 Hint

Think about how the GSI can be used to query different entities efficiently.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this DynamoDB query using GSI overloading

Which option contains a syntax error in the DynamoDB query expression to fetch all orders for customer C789 using GSI1?

DynamoDB
Query parameters example:
IndexName: 'GSI1'
KeyConditionExpression: 'GSI1PK = :pk and begins_with(GSI1SK, :skprefix)'
ExpressionAttributeValues: { ':pk': 'CUSTOMER#C789', ':skprefix': 'ORDER#' }
AKeyConditionExpression: 'GSI1PK = :pk and begins_with(GSI1SK, :skprefix)'
B')xiferpks: ,KS1ISG(htiw_snigeb dna kp: = KP1ISG' :noisserpxEnoitidnoCyeK
CKeyConditionExpression: 'GSI1PK = :pk and GSI1SK begins_with :skprefix'
DKeyConditionExpression: 'GSI1PK = :pk and GSI1SK = :skprefix'
Attempts:
2 left
💡 Hint

Check the syntax for the begins_with function in DynamoDB expressions.

optimization
advanced
2:30remaining
Optimizing queries for many-to-many relationships with GSI overloading

You want to optimize read performance when querying all customers linked to a specific order using a GSI that overloads keys. Which design choice improves query efficiency?

AUse a GSI with partition key as 'ORDER#orderId' and sort key as 'CUSTOMER#customerId' to query customers by order
BUse a scan operation on the main table filtering by order ID prefix
CStore customer and order data in separate tables to avoid GSI overloading
DUse a GSI with partition key as 'CUSTOMER#customerId' and sort key as 'ORDER#orderId' to query customers by order
Attempts:
2 left
💡 Hint

Think about how partition keys affect query speed and filtering.

🔧 Debug
expert
3:00remaining
Debugging missing results in many-to-many GSI queries

You have a DynamoDB table with many-to-many relationships using GSI overloading. You run this query on GSI1 to get all orders for customer C555:

QueryIndex: 'GSI1'
KeyConditionExpression: 'GSI1PK = :pk and begins_with(GSI1SK, :prefix)'
ExpressionAttributeValues: { ':pk': 'CUSTOMER#C555', ':prefix': 'ORDER#' }

But the query returns no results, even though orders exist. What is the most likely cause?

AThe GSI1PK attribute values for orders linked to customer C555 are missing or incorrect in the table items
BThe KeyConditionExpression syntax is invalid and causes the query to fail silently
CThe main table partition key is used instead of the GSI partition key in the query
DThe ExpressionAttributeValues use wrong prefixes like 'ORDER-' instead of 'ORDER#'
Attempts:
2 left
💡 Hint

Check if the GSI attributes are correctly populated for linked items.