user1031186
user1031186

Reputation: 58

Azure cosmos db is faster without partition key

I'm confusing about the partition key with cosmos db. I have a database/container with about 4000 small records. If I try a sql statement with my partition key filter, the RUs and the duration time is larger then without.

Does someone understand this?

in this sample my partition key of the container is /partitionKey

I tried this statement: SELECT * FROM c where c.partitionKey = 'userSettings' And c.deleted =false

Request Charge 50 RUs Document load time 2.15 ms

and then this SELECT * FROM c where c.cosmosEntityName = 'userSettings' And c.deleted =false

Request Charge 5 RUs Document load time 0.38 ms

I expect exactly the opposite results.

Here some screenshots: enter image description here

enter image description here

enter image description here

Upvotes: 3

Views: 3494

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

This question is very specific to the topology of your collection (which Azure support can help with), but generally speaking there are two cases where the latter query on non-partition key property can be lower in RUs than the partition key property:

List item

  • If the query on non-partition key property is incomplete, the RUs may appear lower, but you still need to read results from other partitions to ascertain there are no more results. You would have to click "More Results" in Data Explorer until it is grayed out
  • For this specific query where c.partitionKey = 'userSettings' And c.deleted =false, you should compare RUs with and without a composite index on /partitionKey/? and /deleted/? (https://learn.microsoft.com/azure/cosmos-db/how-to-manage-indexing-policy#composite-indexing-policy-examples). In some cases, you will get lower RUs with the composite index than with the default of /* which only indexes them individually, potentially close to ~5 RUs

Upvotes: 3

Related Questions