2
votes

I created one collection with partition key as "/countryId", in that when i read multiple documents using SQL query i specified FeedOptions { EnableCrossPartitionQuery = true } and query like follows

select * from collection c where (c.countryId=1 or c.countryId=2 or c.countryId=3)

I would like to know how internally execute, i mean

I am specified countryId(partitionKey) in where condition,will it go to that particular partitions only for getting documents?

or

It will go to all partition of collection and check on each document countryId(partitionkey)

Thanks in Advance !!.

1

1 Answers

3
votes

The DocumentDB query will execute against only the partitions that match the filter, not all partitions:

  1. The DocumentDB SDK/gateway will retrieve the partition key metadata for the collection and know that the partition key is countryId, as well as the physical partitions, and what ranges for partition key hashes map to which physical partitions.
  2. During query execution, the SDK/gateway will parse the SQL query and detect that there are filters against the partition key. It will hash the values, find the matching partitions based on its owning partition key ranges. For example, countries 1, 2, and 3 may be all in one physical partition, or three different partions.
  3. The query will be executed in series or parallel by the SDK/gateway based on the configured degree of parallelism. If any post-processing like ORDER BY or aggregation is required, then it will be performed by the SDK/gateway.