【发布时间】: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 中?但要做到这一点并不容易。
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