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

Difference between partition key indicated in query expression and feedoptions in cosmos db

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

出于性能考虑,是否应该在feedoptions选项参数中注明partition key

喜欢不同之处 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.I 中指定分区键 进行了微测试以观察两种解决方案的性能。

第一个:

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());

测试数据:

输出:

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