Reputation: 1046
I am working with Dynamo DB and want to scan one table using filter.Is it possible to scan just particular rows from table by using global secondary index for example?
Upvotes: 2
Views: 782
Reputation: 1166
If you are scanning for a dichotomous attribute, which you say status is null or not, it is possible if you make use of Sparse Indexes and be much more efficient !!
From AWS documents 'best practices for GSI'
Take Advantage of Sparse Indexes
For any item in a table, DynamoDB will only write a corresponding entry to a global secondary index if the index key value is present in the item. For global secondary indexes, this is the index partition key and its sort key (if present). If the index key value(s) do not appear in every table item, the index is said to be sparse.
You can use a sparse global secondary index to efficiently locate table items that have an uncommon attribute. To do this, you take advantage of the fact that table items that do not contain global secondary index attribute(s) are not indexed at all. For example, in the GameScores table, certain players might have earned a particular achievement for a game - such as "Champ" - but most players have not. Rather than scanning the entire GameScores table for Champs, you could create a global secondary index with a partition key of Champ and a sort key of UserId. This would make it easy to find all the Champs by querying the index instead of scanning the table.
Such a query can be very efficient, because the number of items in the index will be significantly fewer than the number of items in the table. In addition, the fewer table attributes you project into the index, the fewer read capacity units you will consume from the index.
Upvotes: 3
Reputation: 169
It's not possible! The scan is always for all rows from the base table, and when you scan an index table as a response you will get only the attributes that are included in that index table.
Example: If you have a table with 1000 rows and attributes: id, name, surname, year, city, zipcode, and you create GSI for that table with primary key "city" and you include "zipcode" as a projected attribute and when you scan that index table again all 1000 rows will be processed but as a response you will get just "city" and "zipcode" for each of the rows. Gain is lowering the throughput but it will cost you monthly for read and write capacity units that you will set up when creating the GSI.
Upvotes: 4