0
0
DynamoDBquery~10 mins

Scan vs Query performance comparison in DynamoDB - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Scan vs Query performance comparison
Start Operation
Use Partition Key
Fetch Matching Items
Return Results
End Operation
Shows how Query uses keys to fetch matching items efficiently, while Scan reads the whole table and filters later.
Execution Sample
DynamoDB
Query: SELECT * FROM table WHERE partition_key = 'A'
Scan: SELECT * FROM table WHERE attribute = 'A'
Query fetches items by partition key directly; Scan reads all items and filters after.
Execution Table
StepOperationItems ReadItems ReturnedPerformance Impact
1Query starts00Fast start, uses partition key
2Query reads matching partition33Reads only relevant items
3Query returns results33Efficient, low cost
4Scan starts00Starts reading entire table
5Scan reads all items103Reads all items, filters later
6Scan returns filtered results103Slower, higher cost
7End--Query is faster and cheaper than Scan
💡 Scan reads all 10 items, Query reads only 3 matching items; Query is more efficient.
Variable Tracker
VariableStartAfter Query Step 2After Scan Step 5Final
Items Read031010
Items Returned0333
Key Moments - 2 Insights
Why does Query read fewer items than Scan?
Because Query uses the partition key to directly access matching items (see execution_table row 2), while Scan reads the entire table (row 5) and filters afterward.
Does Scan always return more items than Query?
No, Scan can return the same number of items as Query (see rows 3 and 6), but it reads more items internally, making it slower and more costly.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, how many items does Query read at step 2?
A3
B10
C0
D5
💡 Hint
Check the 'Items Read' column at step 2 in execution_table.
At which step does Scan finish reading all items?
AStep 4
BStep 5
CStep 6
DStep 3
💡 Hint
Look for 'Scan reads all items' in execution_table step 5.
If the table had 1000 items but only 3 matched the Query, how would Query's 'Items Read' change?
AIt would read 1000 items
BIt would read 0 items
CIt would read 3 items
DIt would read 500 items
💡 Hint
Query reads only matching partition key items, as shown in variable_tracker.
Concept Snapshot
Query uses partition key to fetch matching items directly.
Scan reads the entire table and filters afterward.
Query is faster and cheaper than Scan.
Use Query when you know the partition key.
Scan is costly and slower for large tables.
Always prefer Query for performance.
Full Transcript
This visual execution compares DynamoDB Query and Scan operations. Query uses the partition key to directly fetch matching items, reading fewer items and returning results quickly. Scan reads the entire table, then filters items, resulting in more items read and slower performance. The execution table shows Query reading 3 items and Scan reading 10 items to return the same 3 results. Variable tracking confirms Query reads fewer items. Key moments clarify why Query is more efficient and when Scan returns the same number of items but at higher cost. The quiz tests understanding of items read and performance differences. Remember, Query is best when you know the partition key; Scan should be avoided for large tables due to cost and speed.