DEV Community

Cover image for Boosting Performance: Enhancing Data Scope with fetch XML
Bala Madhusoodhanan
Bala Madhusoodhanan

Posted on

3 2 2 2 2

Boosting Performance: Enhancing Data Scope with fetch XML

Intro:
When working with Microsoft Dataverse and Power Automate, optimizing your queries can significantly improve performance and streamline your workflows. In this blog, we'll explore two essential tips to enhance your data operations: selecting specific columns and utilizing FetchXML. These strategies are part of the broader concept of query anti-patterns, which help avoid common pitfalls and ensure your data retrieval processes are as efficient as possible.

Setup:
When working with Power Automate, it's often crucial to measure the time saved between different steps to optimize performance. One effective way to achieve this is by using ticks, which represent the smallest unit of time in Power Automate. In this guide, we'll walk you through the process of calculating the time saved between two steps using ticks.

ticks(utcNow())

Enter fullscreen mode Exit fullscreen mode

Image description

The setup of the flow is something like this. I have restricted the row count to 100.

Image description

Tip 1:
When working with Dataverse, it's crucial to optimize your queries to ensure efficient data retrieval. One effective way to achieve this is by using the Select Column parameter in your ListRecords operations. Queries that return all columns or include a large number of columns can encounter performance issues due to the size of the dataset or the complexity of the query.

To list 100 records using ListRecords operations the action took 465.1485 milliseconds. While if we put select column parameter the compute was 190.0756, which translates to a 59.12% reduction in execution time.

Tip 2:
Another important optimization technique when working with Dataverse queries is to avoid using the "Order By" clause. While ordering data can be useful in certain scenarios, it adds additional computational overhead to the action. This can lead to slower query execution times and increased server load.

By avoiding the "Order By" clause, you can streamline your queries and reduce the amount of processing required. This is especially beneficial when dealing with large datasets or complex queries. Instead, consider sorting the data after retrieval if necessary, using client-side processing or other methods that don't impact the server performance.
A 69.12% increase in time is observed if you add a "Order By"

Tip 3:
To visually demonstrate the efficiency of FetchXML, I selected 100 records from the Solutions entity in the previous step and looped through the solutioncomponents to retrieve the components. One branch of the Power Automate flow does not use the FetchXML query, while the other branch does.

To further optimize your Dataverse queries, consider using FetchXML. FetchXML is a powerful query language that allows you to manipulate data scope and retrieve precisely the information you need. By leveraging FetchXML, you can enhance the performance of your queries significantly.

This FetchXML query groups the solution components by their type and counts the number of components for each type. It's a powerful way to aggregate data and retrieve summarized information efficiently.

<fetch distinct="false" mapping="logical" aggregate="true">
  <entity name="solutioncomponent">
    <attribute name="componenttype" alias="componenttype" groupby="true" />
    <attribute name="solutioncomponentid" alias="componentcount" aggregate="count" />
 </entity>
</fetch>
Enter fullscreen mode Exit fullscreen mode

Image description

By using FetchXML, you were able to reduce the execution time from 45 seconds to 31 seconds, showcasing a significant performance enhancement.A 30% improvement

Closing Remarks:
By using the select column parameter, avoiding the "Order By" clause, and leveraging FetchXML, you can significantly enhance the performance of your queries. These strategies help reduce computational overhead, streamline data retrieval, and ensure your workflows run smoothly.

Remember, optimizing your queries not only improves execution times but also minimizes server load, leading to better overall performance. Implementing these tips will help you build robust and efficient solutions in Power Automate and Dataverse. Stay tuned for more insights and best practices to keep your data operations running at their best.

Reference:
Query Anti pattern

Top comments (1)

Collapse
 
veilgen_ profile image
Veilgen Security

Great insights on optimizing Dataverse queries! The comparison of execution times before and after applying FetchXML, Select Columns, and avoiding 'Order By' really highlights the impact of these best practices. The 30% improvement using FetchXML is impressive, and the breakdown makes it easy to understand the benefits. Thanks for sharing these valuable performance tips—definitely applying them in my workflows

👋 Kindness is contagious

Please consider leaving a ❤️ or a kind comment on this post if it was useful to you!

Thanks!