Query & Scan
Query DynamoDB tables by partition key or scan with filter expressions.
Overview
DynamoDB provides two ways to read multiple items: Query and Scan. Stackpane supports both operations with a visual interface for building key conditions and filter expressions.
Query vs Scan
Understanding the difference between Query and Scan is important for both performance and cost:
- Query reads items that share a specific partition key value. It is efficient because DynamoDB uses the partition key to locate the data directly. You can optionally add sort key conditions to narrow results further.
- Scan reads every item in the table and optionally applies a filter expression to discard items that do not match. It always examines the entire table (or the entire page), which consumes more read capacity and takes longer on large tables.
Use Query whenever you know the partition key value. Use Scan when you need to browse all items or search across partition keys.
Querying by Partition Key
- Select a table and open the query panel from the toolbar.
- Select Query as the operation mode.
- Enter the partition key value. Stackpane auto-detects the key schema, so the partition key field name and type are pre-filled.
- Click Run to execute the query.
Results appear in the item table, replacing the current view.
Sort Key Conditions
If the table has a sort key, you can add a condition to narrow results:
- Enable the sort key condition toggle.
- Select an operator:
=,<,<=,>,>=,begins_with, orbetween. - Enter the sort key value (or two values for
between). - Click Run.
Sort key conditions are evaluated server-side by DynamoDB, so they reduce the amount of data returned and read capacity consumed.
Scanning with Filters
- Select a table and open the query panel from the toolbar.
- Select Scan as the operation mode.
- Optionally add one or more filter expressions (see below).
- Click Run to execute the scan.
Without filter expressions, a scan returns all items in the table, paginated according to your page size setting.
Adding Filter Expressions
Filter expressions let you narrow scan results by attribute values:
- Click Add Filter to create a filter clause.
- Enter the attribute name to filter on.
- Select an operator from the dropdown.
- Enter the comparison value.
You can add multiple filter clauses. All clauses are combined with AND logic — items must match every clause to be included in the results.
Supported Filter Operators
| Operator | Description | Example |
|---|---|---|
equals | Attribute equals the value | status = "active" |
notEquals | Attribute does not equal the value | status != "deleted" |
greaterThan | Attribute is greater than the value | age > 18 |
lessThan | Attribute is less than the value | price < 100 |
greaterOrEqual | Attribute is greater than or equal to the value | score >= 90 |
lessOrEqual | Attribute is less than or equal to the value | count <= 10 |
in | Attribute matches one of the provided values | category in ["books", "music"] |
Important: Filters and Read Capacity
Filter expressions are applied after DynamoDB reads the data from disk. A filtered scan still reads the entire table — the filter only removes non-matching items from the response. This means a filtered scan consumes the same read capacity as an unfiltered scan. For cost-efficient filtering, use Query with sort key conditions instead of Scan with filters when possible.
Pagination
Both Query and Scan results are paginated:
- Results load in pages based on your configured page size.
- Click Load More at the bottom to fetch the next page.
- Stackpane automatically passes the
LastEvaluatedKeyfrom the previous response to continue from where the last page ended. - When there are no more pages, the Load More button disappears.
Result Limits
Set a maximum number of items to return from a query or scan:
- Enter a value in the Limit field in the query panel.
- DynamoDB stops reading after returning that many items (before applying filters for scans, after key conditions for queries).
Use limits to sample data from large tables without scanning the entire dataset.
Performance Considerations
- Prefer Query over Scan: Query targets a specific partition and is significantly faster and cheaper on large tables.
- Use sort key conditions: Sort key conditions reduce the data read server-side, improving both speed and cost.
- Be cautious with full table scans: Scanning a table with millions of items consumes substantial read capacity and may take a long time. Use pagination and limits to control the scope.
- Filters do not reduce read costs: Filter expressions reduce the data returned to Stackpane but do not reduce the data DynamoDB reads internally. Design your key schema to support your most common access patterns.
Tips
- The query panel remembers your last operation mode and filter settings for the current session
- Use the partition key value from an item’s inspector to quickly query for related items in the same partition
- Combine sort key conditions with filter expressions for precise results within a partition