我正在 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());
测试数据:
输出:
测试显示第二个比第一个消耗的RU更低。我的样本数据太小,我认为它们之间的差距会随着数据的增加而增加。
关于java - 查询表达式中指示的分区键与 cosmos db 中的 feedoptions 中指示的分区键之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56448881/