0
0
DynamoDBquery~20 mins

Sparse index pattern in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sparse Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Querying a sparse index for items with a specific attribute

You have a DynamoDB table with a sparse global secondary index (GSI) on attribute status. Only items with status set appear in the index.

What will the following query on the GSI return?

Query on GSI where status = 'active'
AItems without the status attribute will be returned.
BAll items in the table will be returned regardless of status.
COnly items where the attribute status equals 'active' will be returned.
DThe query will return an error because status is not a primary key.
Attempts:
2 left
💡 Hint

Remember, a sparse index only contains items where the indexed attribute exists.

🧠 Conceptual
intermediate
2:00remaining
Why use a sparse index in DynamoDB?

What is the main advantage of using a sparse index in DynamoDB?

AIt reduces storage and query costs by indexing only a subset of items.
BIt automatically backs up all table data.
CIt speeds up writes by indexing every attribute.
DIt encrypts data stored in the index.
Attempts:
2 left
💡 Hint

Think about what happens when only some items have the indexed attribute.

📝 Syntax
advanced
2:00remaining
Identify the correct DynamoDB GSI definition for a sparse index

Which of the following GSI definitions correctly creates a sparse index on attribute category?

A{ "IndexName": "CategoryIndex", "KeySchema": [{"AttributeName": "category", "KeyType": "HASH"}], "Projection": {"ProjectionType": "ALL"} }
B{ "IndexName": "CategoryIndex", "KeySchema": [{"AttributeName": "category", "KeyType": "HASH"}], "Projection": {"ProjectionType": "INCLUDE", "NonKeyAttributes": ["price"]} }
C{ "IndexName": "CategoryIndex", "KeySchema": [{"AttributeName": "category", "KeyType": "HASH"}], "Projection": {"ProjectionType": "KEYS_ONLY"} }
D{ "IndexName": "CategoryIndex", "KeySchema": [{"AttributeName": "category", "KeyType": "RANGE"}], "Projection": {"ProjectionType": "ALL"} }
Attempts:
2 left
💡 Hint

A sparse index requires the indexed attribute as the partition key (HASH).

optimization
advanced
2:00remaining
Optimizing queries using sparse indexes

You want to efficiently query only items with a priority attribute set to 'high'. Which approach best uses a sparse index?

AScan the entire table and filter items where <code>priority</code> = 'high'.
BCreate a GSI with <code>priority</code> as a sort key and query all items filtering by 'high'.
CCreate a local secondary index on <code>priority</code> without changing the table schema.
DCreate a GSI with <code>priority</code> as the partition key and only items with <code>priority</code> set will appear in the index.
Attempts:
2 left
💡 Hint

Sparse indexes only include items with the indexed attribute as partition key.

🔧 Debug
expert
2:00remaining
Why does querying a sparse index return no results?

You created a sparse GSI on attribute region. You query the GSI for region = 'us-east-1' but get no results, even though items with that region exist in the table.

What is the most likely cause?

ASparse indexes do not support querying by partition key.
BThe items with region 'us-east-1' do not have the region attribute set exactly as the GSI expects.
CThe table does not have any items with region attribute at all.
DThe GSI was created with region as a sort key instead of partition key.
Attempts:
2 left
💡 Hint

Check if the attribute values exactly match the GSI key attribute.