Hi,
I'm trying to optimize a physical inventory generation in NAV2009. Client has 3,000,000+ Item Ledger entries, 65,000+ unique items and 50+ Inventory locations.
I have built a version of the "Calculate Inventory" process that uses a view that I created. The view summarizes the quantities (basically provides a Qty on Hand) and provides the most recent date in the Item Ledger Entries. It also groups by location so I can run the report by a group of locations. That way, if an item has had the most entry, say a year ago, and has a QtyOnHand of 0, then I can skip the rest of the processing. I do need both the most recent posting date and the Qty On Hand in order to filter the items I wish to process.
Here's my view:
Create view [dbo].[CRONUS USA, Inc_$Physical Inventory Select View] as
select "Item No_", "Location Code", MAX([Posting Date]) as [Last Posting Date], sum(Quantity) as QtyOnHand
from [CRONUS USA, Inc_$Item Ledger Entry]
group by [Location Code], [Item No_]
The view runs fast enough in SQL, but if I use the view in a NAV report and run the Performance Monitor against it, each "NEXT" on the view table takes 90% of the processing time (e.g. 900 milliseconds per location/item vs. approx. 80 milleseconds for the rest of the processing, e.g. creating an item journal line), For any single location, the process has to read through 3000-20000+ Items.
As a result, the "Calculate" process runs way longer than I want it to.
I've tried FIND('-') along with NEXT in my code (The record reads for this table are in an "Integer" dataitem with manually-coded "NEXT" commands.) I've also tried FINDSET. There's no difference in performance. Currently, my Caching Record Set is set to 50.
If I can optimize the way NAV reads this view, I potentially can save 80-90% of the processing time.
Anyone have any ideas?
Thx
Comments
As for the view it can be improved in performance as well but the first option the fastest way.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Sorry - I didn't notice the code. Thanks. It might help a bit. Will try.
Peter
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Peter
Thanks for everyone's opinions, though. I appreciate the feedback.
But you could create an indexed view, but that would add a bit of workload to every single update of the Item Ledger Entry table.
You could also change your view to use one of NAV's own indexed views, i.e. ..$Item Ledger Entry$VSIFT$3.
I guess it might help a bit, but I still think you will get the best performance using ADO.
Please let us know if it helps
Peter
I get the same 25896 records back, but it reads only 1/10 (5372 compared to 54473) and the duration is 1/3 (951 compared to 3105).
This is without doing anything to prevent cache reads, and made in SSMS and stats from the SQL Profiler.
My view:
PS: I'm using NAV2009R2 - you might find an even better index in NAV2013.
Peter
My suggestion takes 1,3s and your suggestion takes 3,5s. (measured by currentdatetime in NAV)
It is strange you don't get a different performance with the two views. Could you show your code from the report triggers?
What version are you using, and is it RTC or Classic?
Peter