0
0
DynamoDBquery~20 mins

GSI overloading technique in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GSI Overloading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Querying a GSI with overloaded attributes

You have a DynamoDB table with a Global Secondary Index (GSI) that uses the attribute GSI1PK as the partition key and GSI1SK as the sort key. The table uses GSI overloading where GSI1PK stores different entity types (e.g., 'USER#123', 'ORDER#456').

What will be the output of this query?

Query GSI1 where GSI1PK = 'USER#123' and GSI1SK begins with 'PROFILE#'

Assuming the table has these items:

  • {GSI1PK: 'USER#123', GSI1SK: 'PROFILE#MAIN', Data: 'UserProfileData'}
  • {GSI1PK: 'USER#123', GSI1SK: 'ORDER#789', Data: 'OrderData'}
  • {GSI1PK: 'ORDER#456', GSI1SK: 'PROFILE#MAIN', Data: 'OrderProfileData'}
A[{GSI1PK: 'USER#123', GSI1SK: 'PROFILE#MAIN', Data: 'UserProfileData'}]
B[{GSI1PK: 'USER#123', GSI1SK: 'ORDER#789', Data: 'OrderData'}]
C[{GSI1PK: 'ORDER#456', GSI1SK: 'PROFILE#MAIN', Data: 'OrderProfileData'}]
D[]
Attempts:
2 left
💡 Hint

Remember the query filters on GSI1PK and the sort key prefix.

🧠 Conceptual
intermediate
1:30remaining
Purpose of GSI overloading in DynamoDB

What is the main advantage of using the GSI overloading technique in DynamoDB?

AIt automatically encrypts data stored in the GSI for security.
BIt increases the write throughput of the base table by duplicating data.
CIt allows storing multiple entity types in a single GSI by using a shared partition key attribute with type prefixes.
DIt enables cross-region replication of the GSI data.
Attempts:
2 left
💡 Hint

Think about how overloading helps organize different data types in one index.

📝 Syntax
advanced
2:30remaining
Correct DynamoDB query syntax for GSI overloading

Which of the following DynamoDB query expressions correctly queries a GSI named GSI1 to find all items with GSI1PK = 'ORDER#' and GSI1SK greater than '2023-01-01'?

AKeyConditionExpression: 'GSI1PK = :prefix AND GSI1SK > :date', ExpressionAttributeValues: { ':prefix': 'ORDER#', ':date': '2023-01-01' }
BKeyConditionExpression: 'begins_with(GSI1PK, :prefix) AND GSI1SK > :date', ExpressionAttributeValues: { ':prefix': 'ORDER#', ':date': '2023-01-01' }
CKeyConditionExpression: 'begins_with(GSI1PK, :prefix) OR GSI1SK > :date', ExpressionAttributeValues: { ':prefix': 'ORDER#', ':date': '2023-01-01' }
DKeyConditionExpression: 'GSI1PK >= :prefix AND GSI1SK > :date', ExpressionAttributeValues: { ':prefix': 'ORDER#', ':date': '2023-01-01' }
Attempts:
2 left
💡 Hint

Remember that DynamoDB KeyConditionExpression supports equality on partition key and range conditions on sort key.

optimization
advanced
2:30remaining
Optimizing GSI overloading for query performance

You have a GSI overloaded with multiple entity types distinguished by prefixes in GSI1PK. Queries on one entity type are slow because the GSI contains many items of other types.

Which optimization will improve query performance?

AAdd a filter expression to the query to exclude other entity types after fetching all items.
BCreate separate GSIs for each entity type instead of overloading.
CIncrease the read capacity units (RCUs) of the GSI to handle more queries.
DUse a sort key prefix to narrow down the query range within the overloaded GSI.
Attempts:
2 left
💡 Hint

Think about how to reduce the number of items scanned during the query.

🔧 Debug
expert
3:00remaining
Debugging a failing query on an overloaded GSI

A query on a DynamoDB GSI overloaded with multiple entity types returns no results, even though matching items exist. The query uses begins_with(GSI1PK, :prefix) with :prefix = 'USER#'.

What is the most likely cause of the problem?

AThe table's primary key conflicts with the GSI partition key causing query failure.
BDynamoDB does not support <code>begins_with</code> on partition key in KeyConditionExpression; partition key must be matched exactly.
CThe query is missing a filter expression to include items with <code>GSI1PK</code> starting with 'USER#'.
DThe attribute <code>GSI1PK</code> is not projected into the GSI.
Attempts:
2 left
💡 Hint

Recall DynamoDB query restrictions on partition keys.