Aquila Sands
Aquila Sands

Reputation: 1471

Is specifying the partition key in the SQL equivalent to using FeedOptions.PartitionKey?

Using the SQL api you can specify the partition key in the SQL statement e.g. SELECT * FROM c WHERE c.MyPartitionKey = 'KeyValue' or using FeedOptions.PartitionKey.

Are they equivalent or will one way have a lower RU cost?

I have tried both ways and can't see a difference but the data set is quite small and this may change as the data grows over time.

Upvotes: 2

Views: 342

Answers (2)

Jay Gong
Jay Gong

Reputation: 23782

I did some tests.

Test One: 100 documents

for (int i = 1; i <=100 ; i++) {
     Document doc = new Document();
     doc.setId(i + "");
     if(i%2 == 0)
        doc.set("name", "white");
     else
        doc.set("name", "black");
     documentClient.createDocument("dbs/db/colls/part", doc, null, true);
     System.out.println("insert document No. " + i);
}

query 1:

String sql ="SELECT * FROM c where c.name='black'";
FeedOptions options = new FeedOptions();
FeedResponse<Document> queryResults = documentClient.queryDocuments("dbs/db/colls/part",sql,options);
System.out.println(queryResults.getRequestCharge());

result: 17.44 RUs


query 2:

FeedOptions options = new FeedOptions();
PartitionKey partitionKey = new PartitionKey("black");
options.setPartitionKey(partitionKey);
String sql ="SELECT * FROM c";
FeedResponse<Document> queryResults = documentClient.queryDocuments("dbs/db/colls/part",sql,options);
System.out.println(queryResults.getRequestCharge());

result: 17.44 RUs

Test Two: 1000 documents

for (int i = 1; i <=1000 ; i++) {
         Document doc = new Document();
         doc.setId(i + "");
         if(i%2 == 0)
            doc.set("name", "white");
         else
            doc.set("name", "black");
         documentClient.createDocument("dbs/db/colls/part", doc, null, true);
         System.out.println("insert document No. " + i);
}

query 1 & 2 are both 31.57 RUs

As mentioned in this article, the RUS is related to the operating document size or concurrent throughput. The above two query result sets are not different, so they should have the same RU cost.

Upvotes: 2

Samer Boshra
Samer Boshra

Reputation: 919

Both are equivalent and should have the same RU cost.

Upvotes: 2

Related Questions