cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Community Champion
Community Champion

Multiple calls to SQL VIEW in Gallary - should I collect() first?

I have a very busy gallary.  I have I think 4 lookups into 2 SQL tables.  So, if I have a large number of items in the gallary, it churns quite a while.  Tables in themselves are pretty cheap, with regards to memory (I think?)  At what point does it make sense to Collect() the table into the app, and then make the calls to the collection?  

 

I would really like to only do one Collect(), however, the data is dynamic, and the app needs the latest every time the gallary is updated.  I cant let the data go stale.  

13 REPLIES 13

@martinav I think you have the right idea here to create a SQL View to 'inner join' the data you would have retrieved as a look up. Then bind the gallery to the View. This pattern eliminates the need for any lookup (you might need one at the time of patching, but not while reading).

 

When? I always do it this way. 

 

On the topic of collections, I would only collect if you are having significant perf issues and not many changes are made to the data. Here's some more recommendations:

https://powerapps.microsoft.com/en-us/blog/performance-considerations-with-powerapps/

I use SQL Views for Galleries since I only need a few fields for Gallery and all of them require fields from other tables.  I spent several days running SQL Profiler to see what PowerApps was doing and measuring performance.  I saw that I could cut down Gallery queries by 15-20 times by using ClearCollect.  The user has to refresh collection when they add a new record or change name on record.  In my case users add about 4-5 records a day.   I also have 23 lookup tables that almost never change.  I initialize all collections on OnStart.  All my Detail forms are SQL Views.  I don't use collections on those views since they have lots of fields.

 

If you are using on-premise SQL Server I suggest using SQL Profiler to understand app performance.

 

 

 

 

@Mr-Dang-MSFT,

 

Yes, I am using SQL Views quite heavily.  I noticed my SQL server is running on a VM.  It is currently setup with 2 cores and 16GB.  When making calls, it looks like CPUs max out, and I do see the memory creeping up to 12GB at times.  

 

Do you think increasing resouces on the VM might help? 

 

I can also run traces now with the SQL Profiler.  Any help there to know what to look for?

I'm no expert on SQL Server but in the testing I've done an issue with PowerApps and memory.  It is performing simple queries.  Memory issues happen when you do complex queries on large datasets.

 

You'll need to use Profiler in off hours.  What I do in Profiler:

 

  • Connect to database
  • Get App setup to perform some function like open app.
  • Pause Profiler and erase history.
  • Unpause Profiler
  • Open app
  • Observe profiler
  • Pause Profiler as soon as app has opened.
  • Go back through profile and observe time spent in queries.  You'll see time in a column.  

 

I profiled dozens of actions and kept a spreadsheed of times.  You need to run action several times to get a good feel for it.  I started changing app and measuring changes in performance for different actions.  One interesting thing I noticed that when form intialized it would perform query on DB even though ID was 0.  I added code in app to not do this.  100's of little things.

 

I spent days doing this to get an understanding of PowerApps

@mogulman, this is a very good tip on understanding how SQL and PowerApps work together. As every app's needs are different, profiling will get a more precise answer on requirements.

 

The community would benefit a lot if you could write a blog post on using SQL Profiler with screenshots. @Anonymous can help you get started.

https://powerusers.microsoft.com/t5/PowerApps-Community-Blog/bg-p/PowerAppsBlog

 

 

@mogulman,

 

I have been using the Profiler for a while.  It is quite telling...  I have an app that provides a list of drawings based on search criteria.  I limit results to 100 items, which is reasonable for the type of search that it does.  I have a single lookup into a nested SQL View.  

 

LookUp('[dbo].[VIEW_ALL_PDM_COMBINED_LATEST]',PartNumber=(MD_PartNumber),CurrentStatusID)

When I trigger the gallery to refresh that view... it generates over 23,000 lines of code!!! (Doing a copy from PRofiler, and paste into excel).  I do not notice errors on the SQL side, but, it does take a long time too populate the gallery.  The information it provides is important, but secondary to the search.  So, the table populates, and the information from this lookup updates over the next 10 or so seconds.  

 

Unfortunately, the SQL View has way too many lines to pull it into collect() first.  It exceeds the delegation rule.  

 

Before I even "run" the app in the editor, this command shows a server error.

 

 

image.png

What is strange, is that this command actually works without giveing erroneous results.  No apparent SQL errors either.  

 

I am wondering if there is some way to "mirror" sql tables to Azure, then do my lookups to the SQL table there.  However, I would need Azure to update each time the parent SQL table changed, or something was added new.  I had thought about getting a trial account going there, but I want everything lined up first, so I have it working long enough to give it a fair try.  

 

If you are using Azure SQL DB you can use the Extended Events to see the SQL Statements generated by PowerApps. It is a while since I last did it, so can't give detailed steps, but I did get this working albeit there was a lot of info to sort through to find the SQL Statements being executed.


@martinav wrote:

@mogulman,

 When I trigger the gallery to refresh that view... it generates over 23,000 lines of code!!! (Doing a copy from PRofiler, and paste into excel).  I do not notice errors on the SQL side, but, it does take a long time too populate the gallery.  The information it provides is important, but secondary to the search.  So, the table populates, and the information from this lookup updates over the next 10 or so seconds.  

 


@martinav, when you place a lookup to SQL inside of a gallery that is already directly connected to SQL, you're making repeated calls to SQL that way. You can significantly reduce that by creating a view that already has all the fields you need by joining the right tables and fields.

 

When you create the new View, can you run the profiler again?

@Mr-Dang-MSFT,

 

Ok... I get what you are saying.  My issue... part of my data is somewhat static.  I collect that data, and it gets automatically refreshed every 15 minutes.  The other data in the table is much more dynamic.  I need that to be real-time update.  Thus, the lookups.  It takes a long time to collect() the data, and the live data comes from tables that are over 4,000 lines.

 

I dont know that perhaps I can have a refresh that strips the new sql rows and modified entries, and then join those tables already in a collection?  I think that would take much less time than trying to pull in the entire dataset.  

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,213)