0
0
DynamoDBquery~10 mins

Index projection types (ALL, KEYS_ONLY, INCLUDE) in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Index projection types (ALL, KEYS_ONLY, INCLUDE)
Start: Query on GSI/LSI
Check Projection Type
ALL
Return all attributes
Result Set
When querying a secondary index, DynamoDB checks the projection type to decide which attributes to return: all attributes, only keys, or keys plus some included attributes.
Execution Sample
DynamoDB
Query GSI with ProjectionType = ALL
Query GSI with ProjectionType = KEYS_ONLY
Query GSI with ProjectionType = INCLUDE (attr1, attr2)
Shows how DynamoDB returns different sets of attributes based on the index's projection type during a query.
Execution Table
StepProjection TypeAttributes RequestedAttributes ReturnedNotes
1ALLPartitionKey, SortKey, AttrA, AttrB, AttrCPartitionKey, SortKey, AttrA, AttrB, AttrCReturns all attributes from the base table
2KEYS_ONLYPartitionKey, SortKey, AttrA, AttrB, AttrCPartitionKey, SortKeyReturns only the keys of the index
3INCLUDEPartitionKey, SortKey, AttrA, AttrB, AttrCPartitionKey, SortKey, AttrA, AttrBReturns keys plus included attributes AttrA and AttrB
4INCLUDEPartitionKey, SortKey, AttrA, AttrB, AttrCPartitionKey, SortKey, AttrAIf only AttrA included, returns keys plus AttrA
5KEYS_ONLYPartitionKey, SortKeyPartitionKey, SortKeyQuery only keys, no other attributes
6---Query ends after returning projected attributes
💡 Query completes after returning attributes based on the projection type.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Attributes ReturnedNoneAll attributesOnly keysKeys + included attrsKeys + included attrs or keys only
Key Moments - 3 Insights
Why does a KEYS_ONLY projection return fewer attributes than ALL?
Because KEYS_ONLY projection returns only the partition and sort keys of the index, not the other attributes, as shown in execution_table row 2.
What happens if you query an index with INCLUDE projection but request attributes not included?
Only the keys and the explicitly included attributes are returned; other attributes are not available from the index, as shown in execution_table row 3.
Does ALL projection return attributes not present in the base table?
No, ALL projection returns all attributes from the base table for the items in the index, as shown in execution_table row 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what attributes are returned at step 2 with KEYS_ONLY projection?
AOnly partition and sort keys
BAll attributes including keys
CKeys plus included attributes
DNo attributes
💡 Hint
Refer to execution_table row 2 under 'Attributes Returned'
At which step does the query return keys plus some included attributes?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Check execution_table rows for 'INCLUDE' projection type
If you want to get all attributes from the base table via an index, which projection type should you use?
AKEYS_ONLY
BINCLUDE
CALL
DNone
💡 Hint
See execution_table row 1 for ALL projection
Concept Snapshot
Index Projection Types in DynamoDB:
- ALL: Returns all attributes from the base table.
- KEYS_ONLY: Returns only the index keys (partition and sort keys).
- INCLUDE: Returns keys plus specified non-key attributes.
Choose projection type based on query needs and storage cost.
Full Transcript
When you query a DynamoDB secondary index, the database decides which attributes to return based on the index's projection type. There are three types: ALL returns every attribute from the base table, KEYS_ONLY returns only the partition and sort keys, and INCLUDE returns the keys plus some extra attributes you specify. This choice affects what data you get back and how much storage the index uses. The execution table shows step-by-step what attributes are returned for each projection type during queries.