I am writing a Dynamo Db .NET query with both "Limit" as well as "Filter Expression" as shown below:
var search = testTable.Query(new QueryOperationConfig
{
Filter = new QueryFilter("Name", QueryOperator.BeginsWith, "B"),
IndexName = "IsActive-gsi",
Limit = 5,
PaginationToken = paginationToken,
});
I expect that filter expression should be evaluated first and then limit condition is applied to the filtered result. But query seems to work in other way. That is, Limit condition is getting applied first and then filter expression is applied on the limited result. Due to this, I am not getting the expected result.
For example, say I have 10 rows in a table (with only one column of string type). Say first 5 rows starts with letter "A" and then 6th row starts with letter "B". I have added Limit as 5 and filter expression as "BeginsWith('B')" as shown above in the query. I expect to get at least one result(6th row) but query returns zero results.
My question: Is my query wrong or does Dynamo DB works this way? If it works this way, then how to get around this issue i.e. first apply filter expression on all rows and then apply limit condition, both in a single call to database?