Skip to content

Commit e696322

Browse files
Live publish for 04 June 2024.
2 parents 743996e + 95f9627 commit e696322

File tree

6 files changed

+160
-95
lines changed

6 files changed

+160
-95
lines changed

powerapps-docs/developer/data-platform/TOC.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@
120120
- name: Sample code
121121
displayName: FetchXml, Sample code
122122
href: fetchxml/sample.md
123+
- name: Query using wildcard characters
124+
href: wildcard-characters.md
125+
- name: Query throttling
126+
href: query-throttling.md
127+
- name: Query Hierarchical data
128+
href: query-hierarchical-data.md
129+
- name: Quick find
130+
href: quick-find.md
131+
- name: Saved Queries
132+
href: saved-queries.md
133+
- name: "Use SQL to query data"
134+
href: dataverse-sql-query.md
135+
- name: "Dataverse SQL"
136+
href: how-dataverse-sql-differs-from-transact-sql.md
123137
- name: Bulk Operation messages
124138
displayName: CreateMultiple, UpdateMultiple, UpsertMultiple
125139
href: bulk-operations.md
@@ -145,32 +159,18 @@
145159
href: create-custom-api-solution.md
146160
- name: CustomAPI Tables
147161
href: custom-api-tables.md
162+
- name: Use open types with custom APIs
163+
href: use-open-types.md
148164
- name: "Sample: IsSystemAdmin custom API plug-in"
149165
href: org-service/samples/issystemadmin-customapi-sample-plugin.md
150166
- Name: "Sample: ExportDataUsingFetchXmlToAnnotation custom API plug-in"
151167
href: org-service/samples/export-data-fetchxml-annotation-custom-api-sample.md
152168
- name: Use Custom Process Actions with code
153169
href: workflow-custom-actions.md
154-
- name: Use open types with custom APIs
155-
href: use-open-types.md
156170
- name: Background operations (preview)
157171
href: background-operations.md
158172
- name: Use optional parameters
159173
href: optional-parameters.md
160-
- name: Quick find
161-
href: quick-find.md
162-
- name: "Use SQL to query data"
163-
href: dataverse-sql-query.md
164-
- name: "Dataverse SQL"
165-
href: how-dataverse-sql-differs-from-transact-sql.md
166-
- name: Saved Queries
167-
href: saved-queries.md
168-
- name: Query using wildcard characters
169-
href: wildcard-characters.md
170-
- name: Query throttling
171-
href: query-throttling.md
172-
- name: Query Hierarchical data
173-
href: query-hierarchical-data.md
174174
- name: Files and images overview
175175
href: files-images-overview.md
176176
items:

powerapps-docs/developer/data-platform/fetchxml/optimize-performance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ contributors:
2020

2121
This article describes ways you can optimize performance when retrieving data using FetchXml.
2222

23+
[!INCLUDE [cc-query-antipatterns](../includes/cc-query-antipatterns.md)]
24+
2325
## Late Materialize query
2426

2527
If you select many lookup and computed columns, and you're experiencing performance issues, you can try setting the [fetch element](reference/fetch.md) boolean `latematerialize` attribute. Behind the scenes, this setting breaks the query into smaller parts and reassembles the results before returning them to you.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## Patterns to avoid
2+
3+
Composing optimized queries for Dataverse is vital to ensure applications provide a fast, responsive, and reliable experience. This section describes patterns to avoid and concepts to understand when composing queries for standard tables using the `RetrieveMultiple` message, or messages that have a parameter that inherits from the [QueryBase class](/dotnet/api/microsoft.xrm.sdk.query.querybase). The guidance here might not apply for [Elastic tables](../elastic-tables.md) or when using [Dataverse Search](../search/overview.md).
4+
5+
6+
### Minimize the number of selected columns
7+
8+
Don't include columns you don't need in your query. Queries that return all columns or include a large number of columns can encounter performance issues due to the size of the dataset or complexity of the query.
9+
10+
This practice is especially true for *logical columns*. A logical column contains values that are stored in different database tables. The [AttributeMetadata.IsLogical property](/dotnet/api/microsoft.xrm.sdk.metadata.attributemetadata.islogical) tells you whether a column is a logical column. Queries that contain many logical columns are slower because Dataverse needs to combine the data from other database tables.
11+
12+
13+
### Avoid leading wild cards in filter conditions
14+
15+
Queries that use conditions with leading wild cards (either explicitly, or implicitly with an operator like `ends-with`) can lead to bad performance. Dataverse can't take advantage of database indexes when a query using leading wild cards, which forces SQL to scan the entire table. Table scans can happen even if there are other non-leading wild card queries that limit the result set.
16+
17+
The following example is a FetchXml [condition element](../fetchxml/reference/condition.md) that uses a leading wild card:
18+
19+
```xml
20+
<condition attribute='accountnumber'
21+
operator='like'
22+
value='%234' />
23+
```
24+
25+
The following example is a [QueryExpression](xref:Microsoft.Xrm.Sdk.Query.QueryExpression) [ConditionExpression](xref:Microsoft.Xrm.Sdk.Query.ConditionExpression) that uses a leading wild card:
26+
27+
```csharp
28+
new ConditionExpression("accountnumber", ConditionOperator.Like, "%234")
29+
```
30+
31+
When queries time out and this pattern is detected, Dataverse returns a unique error to help identify which queries are using this pattern:
32+
33+
> Name: `LeadingWildcardCauseTimeout`<br />
34+
> Code: `0x80048573`<br />
35+
> Number: `-2147187341`<br />
36+
> Message: `The database operation timed out; this may be due to a leading wildcard value being used in a filter condition. Please consider removing filter conditions on leading wildcard values, as these filter conditions are expensive and may cause timeouts.`
37+
38+
Dataverse heavily throttles leading wild card queries that are identified as a risk to the health of the org to help prevent outages. [Learn more about query throttling](../query-throttling.md)
39+
40+
If you find yourself using leading wild card queries, look into these options:
41+
42+
- Use [Dataverse search](../search/overview.md) instead.
43+
- Change your data model to help people avoid needing leading wild cards.
44+
45+
[Learn more about using wildcard characters in conditions for string values](../wildcard-characters.md)
46+
47+
48+
### Avoid using formula or calculated columns in filter conditions
49+
50+
[Formula and calculated column](../calculated-rollup-attributes.md#formula-and-calculated-columns) values are calculated in real-time when they're retrieved. Queries that use filters on these columns force Dataverse to calculate the value for each possible record that can be returned so the filter can be applied. Queries are slower because Dataverse can't improve the performance of these queries using SQL.
51+
52+
When queries time out and this pattern is detected, Dataverse returns a unique error to help identify which queries are using this pattern:
53+
54+
> Name: `ComputedColumnCauseTimeout`<br />
55+
> Code: `0x80048574`<br />
56+
> Number: `-2147187340`<br />
57+
> Message: `The database operation timed out; this may be due to a computed column being used in a filter condition. Please consider removing filter conditions on computed columns, as these filter conditions are expensive and may cause timeouts.`
58+
59+
To help prevent outages, Dataverse applies throttles on queries that have filters on calculated columns that are identified as a risk to the health of the environment. [Learn more about query throttling](../query-throttling.md)
60+
61+
62+
### Avoid ordering by choice columns
63+
64+
When you order query results using a choice column, the results are sorted using the localized label for each choice option. Ordering by the number value stored in the database wouldn't provide a good experience in your application. You should know that ordering on choice columns requires more compute resources to join and sort the rows by the localized label value. This extra work makes the query slower. If possible, try to avoid ordering results by choice column values.
65+
66+
### Avoid ordering by columns in related tables
67+
68+
Ordering by columns on related tables makes the query slower because of the added complexity.
69+
70+
Ordering by related tables should only be done when needed to as described here:
71+
72+
- [Order rows using FetchXml](../fetchxml/order-rows.md)
73+
- [Order rows using QueryExpression](../org-service/queryexpression/order-rows.md)
74+
75+
### Avoid using conditions on large text columns
76+
77+
Dataverse has two types of columns that can store large strings of text:
78+
79+
- [StringAttributeMetadata](/dotnet/api/microsoft.xrm.sdk.metadata.stringattributemetadata) can store up to 4,000 characters.
80+
- [MemoAttributeMetadata](/dotnet/api/microsoft.xrm.sdk.metadata.memoattributemetadata) can store a higher number.
81+
82+
The limit for both of these columns is specified using the `MaxLength` property.
83+
84+
You can use conditions on string columns that have a `MaxLength` configured for fewer than 850 characters.
85+
86+
All memo columns or string columns with a `MaxLength` greater than 850 are defined in Dataverse as large text columns. Large text columns are too large to effectively index, which leads to bad performance when included in a filter condition.
87+
88+
Dataverse search is a better choice to query data in these kinds of columns.

powerapps-docs/developer/data-platform/org-service/queryexpression/optimize-performance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ contributors:
1616

1717
This article describes ways you can optimize performance when retrieving data using [QueryExpression](/dotnet/api/microsoft.xrm.sdk.query.queryexpression).
1818

19+
[!INCLUDE [cc-query-antipatterns](../../includes/cc-query-antipatterns.md)]
20+
1921
## Query Hints
2022

2123
> [!IMPORTANT]
Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,58 @@
11
---
2-
title: "Query throttling (Microsoft Dataverse)| Microsoft Docs"
2+
title: "Query throttling (Microsoft Dataverse)"
33
description: "Read about how the server can throttle a query to reduce system performance impact and what you can do about it."
4-
ms.custom: ""
5-
ms.date: 04/29/2021
6-
7-
ms.suite: ""
8-
ms.tgt_pltfrm: ""
9-
ms.topic: "article"
4+
ms.date: 06/04/2024
5+
ms.topic: article
106
applies_to:
117
- "Dynamics 365 (online)"
12-
ms.assetid: fc3ade34-9c4e-4c33-88a4-aa3842c5eee1
13-
caps.latest.revision: 78
14-
author: "pnghub"
8+
author: pnghub
159
ms.subservice: dataverse-developer
16-
ms.author: "gned"
17-
ms.reviewer: "pehecke"
10+
ms.author: gned
11+
ms.reviewer: pehecke
1812
search.audienceType:
1913
- developer
2014
---
2115

2216
# Query throttling
2317

24-
If a specific query creates a disproportional load on the database storing
25-
Microsoft Dataverse data, it can starve the database of resources and negatively impact
26-
performance of all data operations. When this happens Dataverse can start
27-
throttling that particular query which would allow all other scenarios to
28-
perform normally.
18+
If a specific query creates a disproportional load on the database storing Microsoft Dataverse data, it can starve the database of resources and negatively impact performance of all data operations. When this happens, Dataverse starts throttling that particular query to allow all other scenarios to perform normally.
2919

30-
The primary way in which *query throttling* is different from
31-
[Service protection API limits](api-limits.md) is
32-
query throttling targets a specific query that causes a performance degradation while
33-
leaving the rest of the traffic unaffected. If the throttled query
34-
originates from a non-interactive application, throttling is likely to not be
35-
noticeable for end-users. If the query originates from an interactive
36-
application it will affect users that exercise that particular scenario.
20+
The primary way in which *query throttling* is different from [Service protection API limits](api-limits.md) is
21+
query throttling targets a specific query that causes a performance degradation while leaving the rest of the traffic unaffected. If the throttled query originates from a non-interactive application, throttling is likely to not be noticeable for end-users. If the query originates from an interactive application, it affects users that exercise that particular scenario.
3722

3823
## Query throttling behavior
3924

40-
Throttling can manifest in two ways:
25+
Throttling can manifest in three ways:
4126

42-
- A delay is introduced before each execution of the query, making the
43-
scenario that uses it slower
27+
- A delay is introduced before each execution of the query, making the scenario that uses it slower
28+
- Some fraction of attempts to execute the query are failing with any of the following errors:
4429

45-
- Some fraction of attempts to execute the query are failing with a dedicated
46-
error:
30+
|Error code|Hex code|Message|
31+
|---|---|---|
32+
|`-2147187388`|`0x80048544`| `This query cannot be executed because it conflicts with query throttling.`|
33+
|`-2147187132`|`0x80048644`| `This query cannot be executed because it conflicts with Query Throttling; the query uses a leading wildcard value in a filter condition, which will cause the query to be throttled more aggressively.`|
34+
|`-2147186876`|`0x80048744`| `This query cannot be executed because it conflicts with Query Throttling; the query uses a computed column in a filter condition, which will cause the query to be throttled more aggressively.` |
4735

48-
| **Error code** | **Hex code** | **Message** |
49-
|----------------|--------------|--------------------------------------------------------------------------------------------------------------------------------|
50-
| \-2147187388 | 0x80048544 | This query cannot be executed because it conflicts with query throttling. Please refer to [Query throttling](query-throttling.md) |
36+
For more information about more aggressively throttled query patterns like leading wild cards can be found in [Optimize performance using FetchXml](fetchxml/optimize-performance.md) and [Optimize performance using QueryExpression](org-service/queryexpression/optimize-performance.md)
5137

5238
## Common causes
5339

54-
Most of the situations when query throttling is necessary fall into one of the
55-
two broad categories:
40+
Most of the situations when query throttling is necessary fall into one of these two broad categories:
5641

57-
- Some query in a common interactive scenario, for example a saved query used
58-
in a grid or a query executed by a plug-in, is inefficient and requires a lot
59-
of database resources for each execution
42+
- Some query in a common interactive scenario, for example a saved query used in a grid or a query executed by a plug-in, is inefficient and requires a lot of database resources for each execution
6043

61-
- An automated operation, for example data integration involving moving a
62-
large amount of data into or out of Dataverse, executes a query at a very
63-
high rate which consumes a lot of database resources in aggregate even if
64-
each execution is cheap
44+
- An automated operation, for example data integration involving moving a large amount of data into or out of Dataverse, executes a query at a high rate that consumes a lot of database resources in aggregate even if each execution is less expensive
6545

6646
## How to avoid query throttling
6747

68-
Query throttling depends on the query and the scenario where it is executed but there are some common guidelines:
69-
70-
- For slow low-frequency queries, typically used in interactive
71-
applications, the query structure needs to be changed to make it more
72-
efficient
73-
74-
- Some common guidelines for improving the query performance can be found
75-
in [Optimize performance using FetchXml](fetchxml/optimize-performance.md)
76-
77-
- For non-interactive applications the common ways to reduce the database load
78-
are:
48+
Query throttling depends on the query and the scenario where it's executed but there are some common guidelines:
7949

80-
- If [ExecuteMultiple](xref:Microsoft.Xrm.Sdk.Messages.ExecuteMultipleRequest) (or another batching mechanism) is used, the batch
81-
size can be reduced
50+
- For slow low-frequency queries, typically used in interactive applications, the query structure needs to be changed to make it more efficient
8251

83-
- If the application uses concurrency, the number of threads can be reduced
52+
- Some common guidelines for improving the query performance can be found in [Optimize performance using FetchXml](fetchxml/optimize-performance.md)
8453

85-
- A delay between requests can be introduced to reduce the request rate
86-
when neither batching nor concurrency are used
54+
- For non-interactive applications the common ways to reduce the database load are:
8755

56+
- When using [ExecuteMultiple](xref:Microsoft.Xrm.Sdk.Messages.ExecuteMultipleRequest) (or another batching mechanism), reduce the size of the batch
57+
- If the application is multi-threaded, reduce the number of concurrent threads
58+
- If you aren't using batching or concurrent requests, add a delay between requests to reduce the request rate

0 commit comments

Comments
 (0)