Improving BAQ Performance

,

I think this goes here, if not maybe a mod can spilt this into a new thread.

OK @Bart_Elia who can help me out here.

I have a BAQ that runs in a mere 52 +++ seconds.
Here is the trace was able to make the same call as epicor.

I copied the BAQ Query Phrase and created a view.
Created an external datasource BAQ
Now it takes 1.944 seconds awesome right!!!

Now before I jump to create views for all slow BAQ what steps can I try to improve performance. We have a few complex BAQs that are slow. I am guessing they are similar behind the scenes.

1 Like

What does the BAQ look like/ Can you upload the BAQ itself and or post some screenshots?

The reason for this is that you are bypassing all the Epicor Logic (that may be ok, but keep that in mind)
Customer Security
Territory Security
Payroll
Field Security
etc.

2 Likes

Since we cannot see the actual BAQ, we can only guess… but I do know that there are several versions of Epicor where joins containing the COMPANY fields slow down queries. Example, if you query OrderHed, and join Customer, it will be slow until you delete the Company field’s join, and instead add a Table Condition that the company = current company.
So… one thing to try is simply removing the Company from the join. Same thing for “PlantID” field in some queries.

3 Likes

sure here is the BAQ- Pick away

ETK-BOMShort.baq (175.3 KB)

You can see the actual query the BAQ is running by running a trace in SQL profiler.

Is this an artifact of me not having this table? Or are you actually joining to the _UD table (if so why)?

So let me get this straight… Most of the time, adding the company is faster, but sometimes it makes things worse?? :man_facepalming: So much for a best practice!

The joins should be done by an index. Removing or Adding the company is incorrect, the proper answer is to join on the indexes. (if you can)
If you look in the data dictionary it lists all indexes, joining on ANY of these indexes should igve you better performance, not joining on at least an index will require a full table scan.

As an example above joining on just “PartNum” is bad, however joining on any of these combinations should be better

6 Likes

I’m just curious, is it possible that the execution plan stored for the original BAQ was a “bad” or sub-optimal plan and that running the View (which I’ve read does not cache execution plans) runs faster without being forced to follow a possibly bad cached plan?

And from what I’ve read it sounds like Indexed Views can run even faster.

Are we able to create additional Indexes in Epicor to help queries run faster? Maybe that’s what you need for this particular BAQ? (Been watching too many Brent Ozar videos… :slight_smile: )

3 Likes

Just an FYI, the data dictionary will also pick up added indexes. The last one is one that I added.

image

3 Likes

the ud table is not there. must be because I am using UD fields and you don’t have that table.

1 Like

Yes, you are getting that right… we have reported it, and can reproduce it. Best practice says to always include company, but for CUSTOMER we found we could not. Some BAQs went from minutes to seconds.

2 Likes

That funny blue UD widget may be the problem…
I actually ran into that today, only worse. I added a table, added UD Fields to the BAQ, saved, tested, and all was well…
BUT upon returning, i had the UD table showing (it should never be there)… and worse, it was not joined to anything. So… it took even longer.
In E10, there is an ERP view that makes it so that you should not have to refer directly to the Erp.PartXRefVend_UD directly. It should already come along for the ride with its parent.

Thank goodness I saw this post!! I was joining on company with the customer table and it was fast, until some other part of the query changed. Then it was an issue for some reason.

I just ran afoul of the Customer voodoo. We had a BAQ that was running fine for over a year. Then last Wednesday it suddenly started timing out. It was timing out in the REST API as well as in the BAQ Designer. @ERPSysAdmin’s guess that it might have something to do with a cache prompted me to create a new BAQ from scratch, adding features one at a time and testing at every step.

I joined Customer to OrderHed and all was well. The query returned ~500 rows in ~50ms. Then I added a subquery criterion on a custom field on OrderHed. The BAQ became so slow that it couldn’t even return 10 rows before timing out. Removing Company from the Customer join fixed it. Now it runs in ~150ms. @timshuwy, I owe you a beer!

Running 10.2.100.8.

4 Likes

@timshuwy I’ve experienced the same exact thing with Company joins in SQL back in Epicor 9. I thought I was crazy.

Jose, I have a query over UD19 that takes quite a while to run as well. We were reading this post and so we converted this into an external BAQ as a test. And this did substantially improve the speed on this query. Before putting this into our Production environment, however, we want to make sure we understand the pros and cons. A little background is we have one company in Epicor and we don’t use any customer security so everyone can see all customers and we don’t use the payroll function in epicor. Is this a bad idea to change this to an external BAQ and to change some of our other long running queries to external BAQ’s? What is the downside?

Hi, do you have territory security switched on?

No we don’t I don’t think. Where is this setting located?