如果我的 Cosmos DB 有多个分区,是否有任何理由不设置EnableCrossPartitionQuery
为true?
我知道如果运行可能会影响多个分区的查询,这是必要的。但是,如果查询使用有效的分区键并且肯定只会命中一个分区,是否会因为我将该标志设置为 true 而导致性能损失或成本增加呢?
但是,如果查询使用有效的分区键并且肯定只会命中一个分区,是否会因为我将该标志设置为 true 而导致性能损失或成本增加呢?
据我所知,您需要为分区收集设置分区键,即使您仍然设置EnableCrossPartitionQuery
为true,成本也不会改变。因为请求只扫描您已经设置的特定分区。我做了一个样本测试并尝试验证它。
FeedOptions feedOptions = new FeedOptions();
PartitionKey partitionKey = new PartitionKey("A");
feedOptions.setPartitionKey(partitionKey);
feedOptions.setEnableCrossPartitionQuery(true);
FeedResponse<Document> queryResults = client.queryDocuments(
"/dbs/db/colls/part",
"SELECT * FROM c",
feedOptions);
System.out.println("Running SQL query...");
for (Document document : queryResults.getQueryIterable()) {
System.out.println(String.format("\tRead %s", document));
}
System.out.println(queryResults.getRequestCharge());
我想也许你不必为这个问题而挣扎。EnableCrossPartitionQuery
仅当分区集合的查询不限于单个分区键值时才需要使用选项。如果您知道具体的分区键,则无需设置EnableCrossPartitionQuery
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句