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: powerapps-docs/developer/data-platform/includes/cc-query-antipatterns.md
+11-50Lines changed: 11 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -9,38 +9,23 @@ Don't include columns you don't need in your query. Queries that return all colu
9
9
10
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
11
12
-
<!--
13
-
14
-
David: Most lookups are not logical attributes. Lookups include several supporting attributes that are logical, but the API doesn't return data for many of these. I'm talking about the fields that end with *Name.
15
-
16
-
Common Lookups that are also logical are OwningTeam or OwningUser, because they are special.
17
-
18
-
That's why I re-wrote the content below.
19
-
20
-
Queries with many logical attributes (for example, lookups) can also cause queries to be slow because each logical attribute needs to be retrieved from a seperate entity which can make a simple query much more complex and slow.
21
-
22
-
We recommend customers to design their queries to select the bare minimum of columns needed.
23
-
24
-
-->
25
12
26
13
### Avoid leading wild cards in filter conditions
27
14
28
-
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 nonleading wild card queries that limit the result set.
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.
29
16
30
-
The following example is a FetchXml query that uses a leading wild card:
17
+
The following example is a FetchXml [condition element](../fetchxml/reference/condition.md) that uses a leading wild card:
31
18
32
19
```xml
33
-
<fetch>
34
-
<entityname='account'>
35
-
<attributename='accountid' />
36
-
<attributename='accountnumber' />
37
-
<filtertype='and'>
38
-
<conditionattribute='accountnumber'
39
-
operator='like'
40
-
value='%234' />
41
-
</filter>
42
-
</entity>
43
-
</fetch>
20
+
<conditionattribute='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:
When queries time out and this pattern is detected, Dataverse returns a unique error to help identify which queries are using this pattern:
@@ -78,29 +63,6 @@ To help prevent outages, Dataverse applies throttles on queries that have filter
78
63
79
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.
80
65
81
-
<!--
82
-
83
-
jdaly: I don't think this example adds much here.
84
-
85
-
Do you want to mention the fetch element useraworderby attribute?
86
-
That might make for a good example
87
-
88
-
dasuss: I'm conflicted when it comes to useraworderby, yeah its supported and technically works,
89
-
but I don't think its worth doing in place of ordering on the name. We would be adding an order that doesn't
90
-
make logical sense for the customer (ie the state code Number doesn't mean anything of logical value).
91
-
92
-
Example query ordering on the statecode choice column:
93
-
94
-
``` xml
95
-
<fetch distinct='true'>
96
-
<entity name='account'>
97
-
<attribute name='accountnumber' />
98
-
<order attribute='statecode' />
99
-
</entity>
100
-
</fetch>
101
-
```
102
-
-->
103
-
104
66
### Avoid ordering by columns in related tables
105
67
106
68
Ordering by columns on related tables makes the query slower because of the added complexity.
@@ -110,7 +72,6 @@ Ordering by related tables should only be done when needed to as described here:
110
72
-[Order rows using FetchXml](../fetchxml/order-rows.md)
111
73
-[Order rows using QueryExpression](../org-service/queryexpression/order-rows.md)
112
74
113
-
114
75
### Avoid using conditions on large text columns
115
76
116
77
Dataverse has two types of columns that can store large strings of text:
0 commit comments