Scan vs. Query
Learn what Scan and Query commands are and how they can help us search for information.
In DynamoDB, there are several ways to make queries. Some of them are more efficient or consume fewer resources than others. In this lesson, we’re going to see the two most common query forms that we can use to receive information from DynamoDB.
What is a scan?
Scan is an operation that can be run in DynamoDB to receive information from a table. With scan, it’s possible to receive all the stored records. For those who come from the SQL world, this is very similar to doing a select * from table_name
. As you can see, this will generate a complete reading of all the records that are stored, which is very risky in databases where there is too much information due to the impact that this can have on performance and costs. It’s important to remember that DynamoDB has provisioned throughput based on RCUs. For this reason, it’s advisable to avoid the use of this command in production environments.
There is also an option to filter the information that you want to receive. This is done by using the filterExpressions
command. However, the problem with this is that, at the end of the day, the entire table is being traversed. The only difference is that the result will not return all the stored information, but the information that was specified in the filter.
Get hands-on with 1400+ tech skills courses.