I see that IDynamoDBContext
from official AWS SDK for DynamoDb has different methods to query stored data:
Task<T> LoadAsync<T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default (CancellationToken));
AsyncSearch<T> FromQueryAsync<T>(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null);
QueryFilter
passed to QueryOperationConfig
used by FromQueryAsync() has a method for adding query conditions with the first parameter named keyAttributeName.
public class QueryFilter : Filter
{
public void AddCondition(
string keyAttributeName,
QueryOperator op,
params DynamoDBEntry[] values)
...
Does this mean that querying DynamoDb with FromQueryAsync()
set with the correct type of condition (for key attributes) performs as fast as querying data by primary key calling LoadAsync(hashKey)
?
In other words, are calls to method A
and method B
similar in performance?
protected Task<T> A<T>(string hashKey)
{
return _dynamoDbContext.LoadAsync<T>(hashKey,
_consistentReadConfig,
CancellationToken.None);
}
protected async Task<T> B<T>(string hashKey)
{
var queryFilter = new QueryFilter();
queryFilter.AddCondition("HashKeyProperty", QueryOperator.Equal, hashKey); // adding condition for hash key equality
var queryOperationConfig = new QueryOperationConfig
{
Filter = queryFilter
};
var queryOperation = _dynamoDbContext.FromQueryAsync<T>(
queryOperationConfig,
_consistentReadConfig);
var results = await queryOperation.GetNextSetAsync();
return results.SingleOrDefault();
}