Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Azure Table Storage tables guaranteed to sort by Partition/Row?

When I execute this:

query = new azure.TableQuery().top(100).where("PartitionKey eq ?", someKey);

Does this guarantee that these 100 results will be returned in order by RowKey? Everything I read leads me to believe that there is a single order of records, and it's by the PartitionKey + RowKey. My own basic tests seem to confirm that. But I can't find any official documentation that comes right out and says it.

I just need to know if I can rely on that, or if it's something that could potentially change.

like image 460
Joe Enos Avatar asked Jan 30 '23 14:01

Joe Enos


2 Answers

The results will be in lexical order by their RowKeys. One of the official design patterns called Log Tail pattern described here: https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-design-guide#log-tail-pattern

Relies on this exact fact that within a partition the entities would be sorted in lexical order of their RowKey s.

I would ever doubt this is going to change in anyway for basic table storage service.

So an interesting point here is though, if you build solutions on basic table storage relying on lexical sort of RowKeys within a partition and then if you migrate to Cosmos DB table api (eventually) which under the cover relies on document db, will that assumption still hold true.

like image 92
Dogu Arslan Avatar answered May 14 '23 06:05

Dogu Arslan


I can confirm that for Cosmos DB query results returned by the Table API aren't sorted in partition key/row key order as they're in Azure Table storage. - https://learn.microsoft.com/en-us/azure/cosmos-db/faq#where-is-table-api-not-identical-with-azure-table-storage-behavior

I raised this with them and pointed out the contradicting information in other documentation such as the log tail pattern mentioned above and they replied with "The https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-design-guide doc was initially written for Table storage only. Later when Table API in Cosmos DB and Azure Table storage are merged, the docs were brought to Cosmos DB space. I think there are some issues with the existing Table API docs and we are in the process of revamping our docs, will get to the Table API docs soon."

I almost fainted when I read their reply. How on earth can people migrate their apps from Azure Table Storage to CosmosDB without any sorting functionality. All you can really do is point queries which pretty much makes migrating Azure Table Storage to CosmosDB useless for my needs.

If you too would like to see CosmosDB index at least the RowKey in lexicographical order please upvote my CosmosDB suggestion: https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/36124006-table-api-sort

like image 32
Francesco Avatar answered May 14 '23 05:05

Francesco