Query performance within cycle

I have an existential doubt,

about queries within cycles, I'm talking about when we have a very large database (one million records), what is the best way for this algorithm. Call a query outside the cycle and inside the cycle filter with a list filter or make a query inside the cycle

Hii @João Vilelas,

When dealing with large datasets, it is generally recommended to avoid executing queries inside loops or cycles. This is because executing queries inside loops can lead to performance issues, especially when dealing with large databases containing millions of records. 

So right approach will be Call a query outside the cycle and inside the cycle filter the data with a list filter.

Note: if you can send whole list back to client side and then if you use loop and list filter that will also helpful in imporving the performance.

Kind regards,

Sanjay Kushwah

Hey ,

The thing is that when you are calling the sql or aggregate, it will hit the server. If inside a loop you will do that then it will hit the server again and again that is not a good practice.

Instead of that call the sql/aggregate  one time and filter it multiple times using list filter will be faster and efficient.

Thanks & Regards,

Sudip Pal


It is not recommended to use query inside a loop. It will impact the performance of your application. In order to learn more about performance related best practices please go through with this documentation link.




Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.