【问题标题】:Fastest Query on RowKeyRowKey 上最快的查询
【发布时间】:2014-07-24 05:31:33
【问题描述】:

我们所有的表实体的 RowKey 都有自己的 Kinds。
例如在用户表中:

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;  

我现在的问题是,如果记录变大,还会快吗?或者我应该把 Kind 放在 PartitionKey 中?但要做到这一点并不容易。

在这篇文章中说:
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.  

编辑

我刚刚做了一些测试:

PK: M_Sample  
RK: GUID  
500 records  

还有

PK: Sample  
RK: U_GUID  
500 records  

通过这些查询:

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

而且它表明,我必须真正使用 PartitionKey 作为搜索键。

【问题讨论】:

    标签: c# azure azure-table-storage


    【解决方案1】:

    我现在的问题是,如果记录变大,还会快吗?或者 我应该把 Kind 放在 PartitionKey 中吗?但这样做不会 轻松一点。

    不,因为您的查询是全表扫描。您必须在查询中包含 PartitionKey 以获得最快的性能。

    不确定这是否会有所帮助,但在我们的项目中,我们采用了不同的方法。因此,如果我以上面的示例为例,我们将为每个用户存储两条记录(或者换句话说,我们正在对数据进行非规范化):

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

    根据我们想要查询用户的方式,我们选择两个条件之一。

    【讨论】:

    • 你知道任何解释你的方法的文章吗?我觉得很难理解。您的分区键变得更加复杂。另一个问题,RowKey 的价值是什么?
    • 我们引用了 Azure 存储团队的这篇博文:blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/…。我同意数据会更加分散,因为会有很多单项分区。对于 RowKey,这将取决于。如果您的 PartitionKey 是唯一的,您可以将 RowKey 留空。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2020-05-26
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多