Search code examples
azureazure-table-storageazure-tablequery

Azure table query performance with partition key, rowkey and non-index


I have a table query below that search by PK, RK and a non-index key.

Will this slow down database search? Will the search by DOB be faster if it performs on web layer via c#?

        var name = "John";
        var wins = 20;
        var dob = DateTimeOffset.Parse("1999-1-1");
        string usernameFilter2 =
            TableQuery.CombineFilters(
                    TableQuery.CombineFilters(
                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, name),
                        TableOperators.And,
                        TableQuery.GenerateFilterConditionForInt("RowKey", QueryComparisons.Equal, wins)), 
                TableOperators.And,
                TableQuery.GenerateFilterConditionForDate("DateOfBirth", QueryComparisons.GreaterThanOrEqual, dob));

Solution

  • Considering there can be a single entity for a PartitionKey/RowKey combination, I believe your query's 3rd filter criteria is redundant (assuming you've meant to include another attribute there instead of RowKey).

    As far as the speed of the query goes, again considering you're searching for an entity with matching PartitionKey and RowKey, this query will be the fastest. If you remove RowKey from your query and search on PartitionKey and any other non-indexed attribute, it will be slower as the query will be doing a partition scan to find a matching entity.

    You may find this article helpful: https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-design-guide.