Skip to content

Commit f808885

Browse files
committed
update troubleshooting query doc
1 parent ee1584a commit f808885

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed
Binary file not shown.
76.8 KB
Loading

articles/cosmos-db/troubleshoot-query-performance.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This document will use examples that can be recreated using the [nutrition](http
2121

2222
When optimizing a query in Azure Cosmos DB, the first step is always to [obtain the query metrics](profile-sql-api-query.md) for your query. These are also available through the Azure portal as shown below:
2323

24-
![Obtaining query metrics](./media/troubleshoot-query-performance/obtain-query-metrics.jpg)
24+
[ ![Obtaining query metrics](./media/troubleshoot-query-performance/obtain-query-metrics.png) ](./media/troubleshoot-query-performance/obtain-query-metrics.png#lightbox)
2525

2626
After obtaining query metrics, compare the Retrieved Document Count with the Output Document Count for your query. Use this comparison to identify the relevant sections to reference below.
2727

@@ -33,37 +33,37 @@ You can reference the below section to understand the relevant query optimizatio
3333

3434
#### Retrieved Document Count is significantly greater than Output Document Count
3535

36-
a. [Ensure that the indexing policy includes necessary paths](#ensure-that-the-indexing-policy-includes-necessary-paths)
36+
- [Ensure that the indexing policy includes necessary paths](#ensure-that-the-indexing-policy-includes-necessary-paths)
3737

38-
b. [Understand which system functions utilize the index](#understand-which-system-functions-utilize-the-index)
38+
- [Understand which system functions utilize the index](#understand-which-system-functions-utilize-the-index)
3939

40-
c. [Optimize queries with both a filter and an ORDER BY clause](#optimize-queries-with-both-a-filter-and-an-order-by-clause)
40+
- [Optimize queries with both a filter and an ORDER BY clause](#optimize-queries-with-both-a-filter-and-an-order-by-clause)
4141

42-
d. [Optimize queries that use DISTINCT](#optimize-queries-that-use-distinct)
42+
- [Optimize queries that use DISTINCT](#optimize-queries-that-use-distinct)
4343

44-
e. [Optimize JOIN expressions by using a subquery](#optimize-join-expressions-by-using-a-subquery)
44+
- [Optimize JOIN expressions by using a subquery](#optimize-join-expressions-by-using-a-subquery)
4545

4646
<br>
4747

4848
#### Retrieved Document Count is approximately equal to Output Document Count
4949

50-
a. [Avoid cross partition queries](#avoid-cross-partition-queries)
50+
- [Avoid cross partition queries](#avoid-cross-partition-queries)
5151

52-
b. [Optimize queries that have a filter on multiple properties](#optimize-queries-that-have-a-filter-on-multiple-properties)
52+
- [Optimize queries that have a filter on multiple properties](#optimize-queries-that-have-a-filter-on-multiple-properties)
5353

54-
c. [Optimize queries with both a filter and an ORDER BY clause](#optimize-queries-with-both-a-filter-and-an-order-by-clause)
54+
- [Optimize queries with both a filter and an ORDER BY clause](#optimize-queries-with-both-a-filter-and-an-order-by-clause)
5555

5656
<br>
5757

5858
### Query's RU charge is acceptable but latency is still too high
5959

60-
a. [Improving proximity between your app and Azure Cosmos DB](#improving-proximity-between-your-app-and-azure-cosmos-db)
60+
- [Improving proximity between your app and Azure Cosmos DB](#improving-proximity-between-your-app-and-azure-cosmos-db)
6161

62-
b. [Increasing provisioned throughput](#increasing-provisioned-throughput)
62+
- [Increasing provisioned throughput](#increasing-provisioned-throughput)
6363

64-
c. [Increasing MaxConcurrency](#increasing-maxconcurrency)
64+
- [Increasing MaxConcurrency](#increasing-maxconcurrency)
6565

66-
d. [Increasing MaxBufferedItemCount](#increasing-maxbuffereditemcount)
66+
- [Increasing MaxBufferedItemCount](#increasing-maxbuffereditemcount)
6767

6868
## Optimizations for queries where Retrieved Document Count significantly exceeds Output Document Count:
6969

@@ -109,9 +109,9 @@ Retrieved Document Count (60,951) is significantly greater than Output Document
109109

110110
## Ensure that the indexing policy includes necessary paths
111111

112-
Your indexing policy should cover any properties included in WHERE clauses, ORDER BY clauses, JOINs, and most System Functions. The path specified in the index policy should match (case-sensitive) the property in the JSON documents.
112+
Your indexing policy should cover any properties included in `WHERE` clauses, `ORDER BY` clauses, `JOIN`, and most System Functions. The path specified in the index policy should match (case-sensitive) the property in the JSON documents.
113113

114-
If we run a simple query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset, we observe a much lower RU charge when the property in the WHERE clause is indexed.
114+
If we run a simple query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset, we observe a much lower RU charge when the property in the `WHERE` clause is indexed.
115115

116116
### Original
117117

@@ -187,7 +187,7 @@ Other parts of the query may still utilize the index despite the system function
187187

188188
## Optimize queries with both a filter and an ORDER BY clause
189189

190-
While queries with a filter and an ORDER BY clause will normally utilize a range index, they will be more efficient if they can be served from a composite index. In addition to modifying the indexing policy, you should add all properties in the composite index to the ORDER BY clause. This query modification will ensure that it utilizes the composite index. You can observe the impact by running a query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset.
190+
While queries with a filter and an `ORDER BY` clause will normally utilize a range index, they will be more efficient if they can be served from a composite index. In addition to modifying the indexing policy, you should add all properties in the composite index to the `ORDER BY` clause. This query modification will ensure that it utilizes the composite index. You can observe the impact by running a query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset.
191191

192192
### Original
193193

@@ -217,7 +217,7 @@ Indexing policy:
217217

218218
### Optimized
219219

220-
Updated query (includes both properties in the ORDER BY clause):
220+
Updated query (includes both properties in the `ORDER BY` clause):
221221

222222
```sql
223223
SELECT * FROM c
@@ -257,7 +257,7 @@ Updated indexing policy:
257257

258258
## Optimize queries that use DISTINCT
259259

260-
It will be more efficient to find the `DISTINCT` set of results if the duplicate results are consecutive. Adding an ORDER BY clause to the query and a composite index will ensure that duplicate results are consecutive. If you need to ORDER BY multiple properties, add a composite index. You can observe the impact by running a query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset.
260+
It will be more efficient to find the `DISTINCT` set of results if the duplicate results are consecutive. Adding an `ORDER BY` clause to the query and a composite index will ensure that duplicate results are consecutive. If you need to `ORDER BY` multiple properties, add a composite index. You can observe the impact by running a query on the [nutrition](https://github.com/CosmosDB/labs/blob/master/dotnet/setup/NutritionData.json) dataset.
261261

262262
### Original
263263

@@ -283,7 +283,7 @@ ORDER BY c.foodGroup
283283
**RU Charge:** 3.38 RU's
284284

285285
## Optimize JOIN expressions by using a subquery
286-
Multi-value subqueries can optimize `JOIN` expressions by pushing predicates after each select-many expression rather than after all cross-joins in the WHERE clause.
286+
Multi-value subqueries can optimize `JOIN` expressions by pushing predicates after each select-many expression rather than after all cross-joins in the `WHERE` clause.
287287

288288
Consider the following query:
289289

@@ -299,7 +299,7 @@ AND n.nutritionValue < 10) AND s.amount > 1
299299

300300
**RU Charge:** 167.62 RU's
301301

302-
For this query, the index will match any document that has a tag with the name "infant formula", nutritionValue greater than 0, and serving amount greater than 1. The JOIN expression here will perform the cross-product of all items of tags, nutrients, and servings arrays for each matching document before any filter is applied. The WHERE clause will then apply the filter predicate on each `<c, t, n, s>` tuple.
302+
For this query, the index will match any document that has a tag with the name "infant formula", nutritionValue greater than 0, and serving amount greater than 1. The `JOIN` expression here will perform the cross-product of all items of tags, nutrients, and servings arrays for each matching document before any filter is applied. The `WHERE` clause will then apply the filter predicate on each `<c, t, n, s>` tuple.
303303

304304
For instance, if a matching document had 10 items in each of the three arrays, it will expand to 1 x 10 x 10 x 10 (that is, 1,000) tuples. Using subqueries here can help in filtering out joined array items before joining with the next expression.
305305

@@ -315,7 +315,7 @@ JOIN (SELECT VALUE s FROM s IN c.servings WHERE s.amount > 1)
315315

316316
**RU Charge:** 22.17 RU's
317317

318-
Assume that only one item in the tags array matches the filter, and there are five items for both nutrients and servings arrays. The JOIN expressions will then expand to 1 x 1 x 5 x 5 = 25 items, as opposed to 1,000 items in the first query.
318+
Assume that only one item in the tags array matches the filter, and there are five items for both nutrients and servings arrays. The `JOIN` expressions will then expand to 1 x 1 x 5 x 5 = 25 items, as opposed to 1,000 items in the first query.
319319

320320
## Optimizations for queries where Retrieved Document Count is approximately equal to Output Document Count:
321321

0 commit comments

Comments
 (0)