Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对RowKey的最快查询_C#_Azure_Azure Table Storage - Fatal编程技术网

C# 对RowKey的最快查询

C# 对RowKey的最快查询,c#,azure,azure-table-storage,C#,Azure,Azure Table Storage,我们所有的表实体的行键都有各自的类型。 例如,在用户表中: 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 P

我们所有的表实体的行键都有各自的类型。
例如,在用户表中:

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_'  
在林克:

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

我刚刚做了一些测试:

PK: M_Sample  
RK: GUID  
500 records  

关于这些问题:

PartitionKey gt 'M_' and PartitionKey lt 'N_'      --- 26 seconds  
RowKey gt 'U_' and RowKey lt 'V_'               ----- 36 seconds
这表明,我必须使用PartitionKey作为搜索键

我现在的问题是,如果记录变大,速度还会快吗?或 我应该把那种放在分区键里吗?但这样做是行不通的 放松点

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

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

  • PartitionKey=yahoo.com;RowKey=U_user1
  • PartitionKey=U_user1;RowKey=yahoo.com

  • 根据我们想要查询用户的方式,我们从两个标准中选择一个。

    您知道任何解释您方法的文章吗?我觉得很难理解。您的partitionkey变得更加复杂。另一个问题,RowKey的价值是什么?我们引用了Azure存储团队的这篇博文:。我同意数据将更加分散,因为将有许多单个项分区。对于RowKey,这将取决于。如果您的PartitionKey是唯一的,您可以将RowKey留空。
    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