Performance when filtering huge records

Andwian
Member Posts: 627
Dear Experts,
I have a very huge number of Customer Ledger Entries, and these lines of codes:
It will take about 15 secs. to do a Release Document.
I have also tried to change the use of FINDFIRST with recCustLedgerEntries.ISEMPTY, but no significant difference in performance.
Then I try this way:
This way, the running time is about 5 secs.
Any other brilliant ideas to get a better performance?
I am afraid with this very rapid growth records in this table in the future will lead to slow down in performance.
Thank you.
I have a very huge number of Customer Ledger Entries, and these lines of codes:
ReleaseSalesDoc - OnRun ... recCustLedgerEntries.RESET; recCustLedgerEntries.SETRANGE("Customer No.","Sell-to Customer No."); recCustLedgerEntries.SETFILTER("Due Date",'<%1',"Document Date")); recCustLedgerEntries.SETFILTER("Remaining Amt. (LCY)",'>0'); IF recCustLedgerEntries.FINDFIRST THEN ...
It will take about 15 secs. to do a Release Document.
I have also tried to change the use of FINDFIRST with recCustLedgerEntries.ISEMPTY, but no significant difference in performance.
Then I try this way:
recCust.GET(Rec."Sell-to Customer No."); IF recCust.GETFILTER("Date Filter") = '' THEN recCust.SETFILTER("Date Filter",'..%1',"Document Date"); recCust.CALCFIELDS("Balance Due (LCY)"); IF recCust."Balance Due (LCY)" > 0 THEN
This way, the running time is about 5 secs.
Any other brilliant ideas to get a better performance?
I am afraid with this very rapid growth records in this table in the future will lead to slow down in performance.
Thank you.
Regards,
Andwian
Andwian
0
Comments
-
Try this
recCustLedgerEntries.RESET; recCustLedgerEntries.SETCURRENTKEY("Customer No.", Open, Positive, "Due Date", "Currency Code"); recCustLedgerEntries.SETRANGE("Customer No.","Sell-to Customer No."); recCustLedgerEntries.SETRANGE(Open, TRUE); recCustLedgerEntries.SETFILTER("Due Date",'<%1',"Document Date")); recCustLedgerEntries.SETFILTER("Remaining Amt. (LCY)",'>0'); IF recCustLedgerEntries.FINDFIRST THEN
0 -
What would be interesting to know is what happens after the FINDFIRST in the first code snippet. If you really use the first record for something you can use FINDFIRST. If you only use it to find out if records exist, you should use NOT ISEMPTY for better performance.0
-
As Eric P suggested: As a gernal rule: Always use SETCURRENTKEY.
It depends very much on your NAV version/Build and the version of SQL server (if you use it) how slow or fast it will be without the SETCURRENTKEY.
Also: In a SETCURRENTKEY always use the full key and not only the first 2 or 3 fields.Frank Dickschat
FD Consulting0 -
FDickschat wrote:[...]
Also: In a SETCURRENTKEY always use the full key and not only the first 2 or 3 fields.0 -
Shedman wrote:I wouldn't use all fields, but include all fields that your are filtering on. That way if fields are removed from or added to your key, you don't have to change all references to that key.0
-
Shedman wrote:What would be interesting to know is what happens after the FINDFIRST in the first code snippet. If you really use the first record for something you can use FINDFIRST. If you only use it to find out if records exist, you should use NOT ISEMPTY for better performance.Andwian wrote:I have also tried to change the use of FINDFIRST with recCustLedgerEntries.ISEMPTY, but no significant difference in performance.FDickschat wrote:As Eric P suggested: As a gernal rule: Always use SETCURRENTKEY.
It depends very much on your NAV version/Build and the version of SQL server (if you use it) how slow or fast it will be without the SETCURRENTKEY.
Also: In a SETCURRENTKEY always use the full key and not only the first 2 or 3 fields.Shedman wrote:Actually, you should specify the exact key as it exist on the table. When you don't specify all fields of the key, SQL Server might revert to a clustered index scan, which is never good for performance.Regards,
Andwian0 -
recCustLedgerEntries.SETFILTER("Remaining Amt. (LCY)",'>0');
Isn't "Remainging Amt. (LCY)" calculated field? ;-) Filtering on it will be each time time-consuming...0 -
That means e.g. if your key is "No.",Open,"Posting Group","Posting Date" then it is possible to use only the the first field(s) like
SETCURRENTKEY("No.",Open);
You could omit some of the last fields of the key. NAV will search for the right key that matches with the given fields. But on SQL the server possibly will use a clustered index scan. That might turn to a significant loss of performance."Money is likewise the greatest chance and the greatest scourge of mankind."0 -
einsTeIn.NET wrote:That means e.g. if your key is "No.",Open,"Posting Group","Posting Date" then it is possible to use only the the first field(s) like
SETCURRENTKEY("No.",Open);
You could omit some of the last fields of the key. NAV will search for the right key that matches with the given fields. But on SQL the server possibly will use a clustered index scan. That might turn to a significant loss of performance.einsTeIn.NET wrote:That might turn to a significant loss of performance.Regards,
Andwian0 -
Andwian wrote:Anyway, is it about next future performance, or just "that time" performance?"Money is likewise the greatest chance and the greatest scourge of mankind."0
-
einsTeIn.NET wrote:Each time you execute that SETCURRENTKEY statement.
Danke, einsTeIn.NET!
Glückliches neues JahrRegards,
Andwian0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions