2014-07-24 39 views
0

我們所有的表實體的RowKey都有它們的種類。
例如在用戶表:RowKey上最快的查詢

PK: yahoo.com 
RK: U_user1  ----------- the kind is 'U' it means User 

PK: yahoo.com 
RK: U_user2 

PK: yahoo.com 
RK: U_user3 

PK: Store1 
RK: M_user4  ----------- the kind is 'M' it means Merchant 

PK: Store1 
RK: M_user5 

PK: Store1 
RK: M_user6 

PK: Store2 
RK: M_user7 

如果我想搜索所有用戶不準確知道PartitionKey,我會做這樣的:

在Azure存儲資源管理器:

RowKey gt 'U_' and RowKey lt 'V_' 

在LINQ:

var list = from e in dao.Table() 
    where string.Compare(e.RowKey, "U_") > 0 && string.Compare(e.RowKey, "V_") < 0 
    select e; 

我的問題1現在是,如果記錄變大,它仍然會很快嗎?或者我應該把這種類在PartitionKey?但這樣做並不容易。

它說,這篇文章在:

PK: M_Sample 
RK: GUID 
500 records 

而且


http://blog.maartenballiauw.be/post/2012/10/08/What-PartitionKey-and-RowKey-are-for-in-Windows-Azure-Table-Storage.aspx

Less fast: querying on only RowKey. Doing this will give table storage no pointer on 
which partition to search in, resulting in a query that possibly spans multiple partitions, 
possibly multiple storage nodes as well. Wihtin a partition, searching on RowKey is still 
pretty fast as it’s a unique index. 

編輯

我只是在做一些測試

帶着這些疑問:

PartitionKey gt 'M_' and PartitionKey lt 'N_'  --- 26 seconds 
RowKey gt 'U_' and RowKey lt 'V_'    ----- 36 seconds 

它表明,我必須真正使用PartitionKey作爲搜索關鍵字。

回答

1

我現在的問題是,如果記錄變大,它仍然會很快嗎?或 我應該把這種在PartitionKey?但這樣做不會很容易 。

不,因爲您的查詢是dong全表掃描。您需要必須在您的查詢中包含PartitionKey以獲得最快的性能。

不知道這是否會有所幫助,但在我們的項目中,我們採取了不同的方法。因此,如果我以上述示例爲例,我們爲每個用戶存儲兩條記錄(或者換句話說,我們正在非規範化數據):

  1. PartitionKey = yahoo.com; RowKey = U_user1
  2. PartitionKey = U_user1; RowKey = yahoo.com

根據我們要查詢用戶的方式,我們選擇兩個標準之一。

+0

你知道任何解釋你的方法的文章嗎?我覺得很難理解。你的分區鍵變得更加複雜。另一個問題,RowKey的價值是什麼? – fiberOptics

+0

我們從Azure存儲團隊引用此博客文章:http://blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/how-to-get-most-out-of-windows-azure-tables的.aspx。我同意數據將更加分散,因爲會有很多單個項目分區。對於RowKey,這取決於。如果您的PartitionKey是唯一的,您可以將RowKey留空。 –

+0

+1。感謝您的鏈接。您可能還想看到我的編輯.. – fiberOptics