簡體   English   中英

查詢表達式中指示的分區鍵與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 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低於第一個消耗的RU,我的樣本數據太小,我認為它們之間的差距會隨着數據的增加而增加。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM