java - 查询表达式中指示的分区键与 cosmos db 中的 feedoptions 中指示的分区键之间的差异

标签 java azure-cosmosdb database-partitioning azure-cosmosdb-sqlapi

我正在 cosmos db 中调用“queryDocuments(String collectionLink, String query, FeedOptions options)” API,以使用分区键执行一些 SQL 查询。我想知道应该在哪里指示分区键、查询字符串或 feedoptions?

出于性能考虑,我想知道是否应该在 feedoptions options 参数中指明分区键

喜欢差异 queryDocuments(collectionLink, "SELECT * FROM root WHERE id = xxx AND partitionkey = XXX", null); 或者 feedoptions.setpartitionkey(PK); queryDocuments(collectionLink, "SELECT * FROM root WHERE id = xxx", feedoptions);

感谢您的回答!

最佳答案

我建议您在 FeedOptions 中指定分区键。我做了一个微观测试来观察这两种解决方案的性能。

第一个:

String name = "A";
FeedResponse<Document> feedResponse = client
      .queryDocuments("dbs/db/colls/part",
                        "SELECT * FROM c WHERE c.name ='" + name + "'", null);
System.out.println(feedResponse.getRequestCharge());

第二个:

FeedOptions queryOptions = new FeedOptions();
PartitionKey partitionKey = new PartitionKey("/A");
queryOptions.setPartitionKey(partitionKey);
FeedResponse<Document> feedResponse1 = client
      .queryDocuments("dbs/db/colls/part",
                    "SELECT * FROM c ", queryOptions);
System.out.println(feedResponse1.getRequestCharge());

测试数据:

enter image description here

输出:

enter image description here

测试显示第二个比第一个消耗的RU更低。我的样本数据太小,我认为它们之间的差距会随着数据的增加而增加。

关于java - 查询表达式中指示的分区键与 cosmos db 中的 feedoptions 中指示的分区键之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56448881/

相关文章:

postgresql - 在 Postgresql 中创建分区表

java - JPA 标准查询 : writing query with array operators

java - 填充和排序列表 <?扩展条款与条件>

azure - 无法使用 Azure 上托管的 .NET SDK 连接到文档数据库 : The input authorization token can't serve the request

azure-cosmosdb - 如果分区键值为 null,Azure Cosmos 会发生什么情况

spring-boot - 如何在微服务中的数据库(服务的每个实例的每个数据库)之间同步数据?

java - 来自 LiveData 的 Spinner 适配器

java - 基于名称的 Spring Javaconfig Autowiring 不起作用

powershell - 在 powershell 中使用 Azure CLI 创建 CosmosDB

更新 (ALTER) 另一个函数/过程的函数/过程