performance - 如果我们已经将分区键设置到 FeedOption 中,查询是否应该包含分区键?

标签 performance linq azure-cosmosdb

我正在使用带有分区键 =“deviceId”的文档数据库。
下面的2个代码有什么不同:

var fo = new FeedOption{ PartitionKey= new PartitionKey("A1234") };
var partitionKeyInQuery= dbClient.CreateDocumentQuery(d => d.deviceId = "A1234" and d.type==1, fo);
var noPartitionKeyInQuery = dbClient.CreateDocumentQuery(d => d.type==1, fo);

在 FeedOption 中应用 PartitionKey 时,我应该在 WHERE 子句中添加“deviceId”吗?

最佳答案

我相信性能上没有区别。 RequestCharge 是相同的, where 子句使查询分区特定,即消除跨分区查询。

从文档:

查询分区容器

在分区容器中查询数据时,Cosmos DB 会自动将查询路由到对应的分区 到过滤器中指定的分区键值(如果有) .例如,此查询仅路由到包含分区键“XMS-0001”的分区。

// Query using partition key
IQueryable<DeviceReading> query = client.CreateDocumentQuery<DeviceReading>(
    UriFactory.CreateDocumentCollectionUri("db", "coll"))
    .Where(m => m.MetricType == "Temperature" && m.DeviceId == "XMS-0001");

https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-partition-data

关于performance - 如果我们已经将分区键设置到 FeedOption 中,查询是否应该包含分区键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52050064/

相关文章:

javascript - 关于JavaScript中闭包/封装效率的问题

java - 从属性文件读取 v/s HashMap 查找

python - 如何使用 python 在循环中有效地调用函数?

python - 改善 python numpy 代码的运行时间

c# - C#-添加到字符串[]成员

linq - 基于组合框值构建动态LINQ查询

python - 当 "id"绑定(bind)点在 cosmosDB 集合中没有相应的项目时,用 python 编写的 Azure 函数有 500

c# - 将 Entity Framework Core 的 CosmosDB 提供程序与 Azure 表结合使用时出错

c# - 附加的 linq 查询的等效 T-SQL 选择查询是什么?

azure - 从 azure documentDB 中的嵌入数组中选择单个字段