You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/how-to-query-container.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This article explains how to query a container (collection, graph, or table) in
14
14
15
15
## In-partition query
16
16
17
-
When you query data from containers, if the query has a partition key filter specified, Azure Cosmos DB handles the query automatically. It routes the query to the [physical partitions](partition-data.md#physical-partitions) corresponding to the partition key values specified in the filter.
17
+
When you query data from containers, if the query has a partition key filter specified, Azure Cosmos DB automatically optimizes the query. It routes the query to the [physical partitions](partition-data.md#physical-partitions) corresponding to the partition key values specified in the filter.
18
18
19
19
For example, consider the below query with an equality filter on `DeviceId`. This query has an equality filter that includes `DeviceId`. If we run this query on a container partitioned on `DeviceId`, this query will filter to a single partition.
20
20
@@ -28,7 +28,7 @@ As with the earlier example, this query will also filter to a single partition.
28
28
SELECT*FROM c WHEREc.DeviceId='XMS-0001'ANDc.Location='Seattle'
29
29
```
30
30
31
-
Here's a query that has a range filter on the partition key and will not be scoped to a single physical partition. In order to be an in-partition query, the query must have an equality filter that includes the partition key:
31
+
Here's a query that has a range filter on the partition key and won't be scoped to a single physical partition. In order to be an in-partition query, the query must have an equality filter that includes the partition key:
32
32
33
33
```sql
34
34
SELECT*FROM c WHEREc.DeviceId>'XMS-0001'
@@ -44,27 +44,27 @@ The following query doesn't have a filter on the partition key (`DeviceId`). The
44
44
45
45
Each physical partition has its own index. Therefore, when you run a cross-partition query on a container, you are effectively running one query *per* physical partition. Azure Cosmos DB will automatically aggregate results across different physical partitions.
46
46
47
-
The indexes in different physical partitions are completely independent from one another. There is no global index in Azure Cosmos DB.
47
+
The indexes in different physical partitions are independent from one another. There is no global index in Azure Cosmos DB.
48
48
49
49
## Parallel cross-partition query
50
50
51
51
The Azure Cosmos DB SDKs 1.9.0 and later support parallel query execution options. Parallel cross-partition queries allow you to perform low latency, cross-partition queries.
52
52
53
53
You can manage parallel query execution by tuning the following parameters:
54
54
55
-
- **MaxConcurrency**: Sets the maximum number of simultaneous network connections to the container's partitions. If you set this property to `-1`, the SDK manages the degree of parallelism. If the `MaxConcurrency` is not specified orset to `0`, there is a single network connection to the container's partitions.
55
+
- **MaxConcurrency**: Sets the maximum number of simultaneous network connections to the container's partitions. If you set this property to `-1`, the SDK manages the degree of parallelism. If the `MaxConcurrency`set to `0`, there is a single network connection to the container's partitions.
56
56
57
57
- **MaxBufferedItemCount**: Trades query latency versus client-side memory utilization. If this option is omitted or to set to -1, the SDK manages the number of items buffered during parallel query execution.
58
58
59
59
Because of the Azure Cosmos DB's ability to parallelize cross-partition queries, query latency will generally scale well as you add [physical partitions](partition-data.md#physical-partitions). However, RU charge will increase significantly as the total number of physical partitions increases.
60
60
61
-
When you run a cross-partition query, you are essentially doing a separate query per individual physical partition. While cross-partition queries queries will utilize the index, if available, they are still not nearly as efficient asin-partition queries.
61
+
When you run a cross-partition query, you are essentially doing a separate query per individual physical partition. While cross-partition queries queries will use the index, if available, they are still not nearly as efficient asin-partition queries.
62
62
63
63
## Useful example
64
64
65
65
Here's an analogy to better understand cross-partition queries:
66
66
67
-
Let's imagine you are a delivery driver that has to delivery packages to different apartment complexes. Each apartment complex has a list on the premises that has all of the resident's unit numbers. We can compare each apartment complex to a physical partition and each list to the physical partition's index.
67
+
Let's imagine you are a delivery driver that has to deliver packages to different apartment complexes. Each apartment complex has a list on the premises that has all of the resident's unit numbers. We can compare each apartment complex to a physical partition and each list to the physical partition's index.
68
68
69
69
We can compare in-partition and cross-partition queries using this example:
70
70
@@ -74,23 +74,23 @@ If the delivery driver knows the correct apartment complex (physical partition),
74
74
75
75
### Cross-partition query (fan-out)
76
76
77
-
If the delivery driver does not know the correct apartment complex (physical partition), they'll need to drive to every single apartment building and check the list with all of the resident's unit numbers (the index). Once they arrive at each apartment complex, they'll still be able to utilize the list of the address of each resident. However, they will need to check every apartment complex's list, whether any package recipients live there or not. This is how cross-partition queries work. While they can utilize the index (don't need to knock on every single door), they must separately check the index for every physical partition.
77
+
If the delivery driver does not know the correct apartment complex (physical partition), they'll need to drive to every single apartment building and check the list with all of the resident's unit numbers (the index). Once they arrive at each apartment complex, they'll still be able to use the list of the addresses of each resident. However, they will need to check every apartment complex's list, whether any package recipients live there or not. This is how cross-partition queries work. While they can use the index (don't need to knock on every single door), they must separately check the index for every physical partition.
78
78
79
79
### Cross-partition query (scoped to only a few physical partitions)
80
80
81
-
If the delivery driver knows that all package recipients live within a certain few apartment complexes, they won't need to drive to every single one. While this will still require more work than visiting just a single building, the delivery driver still saves significant timeand effort. If a query has the partition key in its filter with the `IN` keyword, it will only check the relevant physical partition's indexes for data.
81
+
If the delivery driver knows that all package recipients live within a certain few apartment complexes, they won't need to drive to every single one. While driving to a few apartment complexes will still require more work than visiting just a single building, the delivery driver still saves significant timeand effort. If a query has the partition key in its filter with the `IN` keyword, it will only check the relevant physical partition's indexes for data.
82
82
83
83
## Avoiding cross-partition queries
84
84
85
-
For most containers, it is inevitable that you will have some cross-partition queries. This is ok! Nearly all query operations are supported across partitions (both logical partition keys and physical partitions). Azure Cosmos DB also has many optimizations in the query engine and client SDK's to parallelize query execution across physical partitions.
85
+
For most containers, it's inevitable that you will have some cross-partition queries. Having some cross-partition queries is ok! Nearly all query operations are supported across partitions (both logical partition keys and physical partitions). Azure Cosmos DB also has many optimizations in the query engine and client SDKs to parallelize query execution across physical partitions.
86
86
87
-
For most read-heavy scenarios, we recommend simply selecting the most common property in your query filters. In addition, you should make sure your partition key adheres to other [partition key selection best practices](partitioning-overview.md#choose-partitionkey).
87
+
For most read-heavy scenarios, we recommend simply selecting the most common property in your query filters. You should also make sure your partition key adheres to other [partition key selection best practices](partitioning-overview.md#choose-partitionkey).
88
88
89
-
Avoiding cross-partition queries matters typically only matters with large containers. You are charged a minimum of about 2.5 RU's each time you check a physical partition's index for results, even if no items in the physical partition match the query's filter. Therefore, if you have only one (or just a few) physical partitions, cross-partition queries will not consume significantly fewer RU's than in-partition queries.
89
+
Avoiding cross-partition queries typically only matters with large containers. You are charged a minimum of about 2.5 RU's each time you check a physical partition's index for results, even if no items in the physical partition match the query's filter. As such, if you have only one (or just a few) physical partitions, cross-partition queries will not consume significantly fewer RU's than in-partition queries.
90
90
91
91
The number of physical partitions is tied to the amount of provisioned RU's. Each physical partition allows for up to 10,000 provisioned RU's and can store up to 50 GB of data. Azure Cosmos DB will automatically manage physical partitions for you. The number of physical partitions in your container is dependent on your provisioned throughput and consumed storage.
92
92
93
-
Therefore, you should try to avoid cross-partition queries if your workload meets the criteria below:
93
+
You should try to avoid cross-partition queries if your workload meets the criteria below:
0 commit comments