简体   繁体   中英

Querying azure table to get last inserted data for a partition

I have a azure storage table which stores the status updated from multiple sources. I have the partition key as the source ID (which is unique for each source). Now for any given source ID I want to access the last updated status. I can do that by sorting the results from a partition by timestamp in descending order and getting the first record but it doesn't seem to be very performant. Each partition can have over 1000 records and sorting doesn't seem to be the best way.

Is there any other way how I can achieve the same in an efficient manner? Are the entities in a partition already sorted by certain row key that I can leverage?

In the RowKey insert a value that is "decreasing" over time. I use this:
myentity.RowKey = String.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks) ;

Now you can execute a select with a where condition on the primary key, followed by a Take(1). This will give you the most recent item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM