How To increase performance by reducing DB-reads?

Administrator
Member, Moderator, Administrator Posts: 2,506
How To increase performance by reducing DB-reads?
http://www.mibuso.com/howtoinfo.asp?FileID=14
Discuss this How To here.
http://www.mibuso.com/howtoinfo.asp?FileID=14
Discuss this How To here.
0
Comments
-
SQL client doesn't do a second read if the record is already in cache.
Run the following code and turn on Profiler, you'll see only two SELECT statements even though It's looping 10 times.For I := 0 to 10 do begin Item.get('1000'); Item.get('1100'); if not confirm('continue?') then begin error(''); end; end;
0 -
ara3n wrote:SQL client doesn't do a second read if the record is already in cache.
Run the following code and turn on Profiler, you'll see only two SELECT statements even though It's looping 10 times.For I := 0 to 10 do begin Item.get('1000'); Item.get('1100'); if not confirm('continue?') then begin error(''); end; end;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Same Results.
For I := 1 to 2000 do begin GLEntry.get(I); end; For I := 1 to 2000 do begin GLEntry.get(I); if not confirm('continue?') then begin error(''); end; end;
The second loop does not create any sql queries. Same results.
Now if you are modifying the records, then it's another story.[/quote]0 -
I did some tests with a small amount of records (up to 10000) and the times are comparable between the GET and the GetRecord on my portable.
Once I get over 100000 records, the differences get more substantial.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Waldo wrote:It's a good howto, and a creative way of programming ... but I think it's only interesting as a "last resort"... . It's quite a complex way of programming (not really "lazy programming") don't you think?
And if you have a library in which you keep all functions and add a function when a project needs a new table, and then take that library in that project, also the next project will take profit.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
If you had to do it I would rather do it like this and keep the temporary records local.
recItemLedgerEntry.RESET; recItemLedgerEntry.SETCURRENTKEY(".."); recItemLedgerEntry.SETRANGE(".."); recItemLedgerEntry.SETRANGE(".."); recItemLedgerEntry.SETFILTER(".."); IF recItemLedgerEntry.FINDSET THEN begin recInventorySetup.GET(); REPEAT IF NOT tempItem.GET("Item No.") THEN BEGIN recItem.GET("Item No."); tempItem := recitem; tempItem.INSERT; END; IF NOT tempLocation.GET("Location Code") THEN BEGIN recLocation.GET("Location Code"); tempLocation := recLocation; tempLocation.INSERT; end; UNTIL recItemLedgerEntry.NEXT = 0; end;
0 -
hedegaard wrote:If you had to do it I would rather do it like this and keep the temporary records local.
But Locations-table doesn't change that often. And with the singleinstance codeunit, you read each location once per session (or until you change company).Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
First a performance tweak: for small tables (like the location table) it's better to read the whole table in one go into your single instance codeunit. It's a lot slower going back to the DB every time. This will also make the code a little more simple.
Secondly on the NAS if you want to be able to clear the temp tables occasionally you can store the non-single instance codeunit in a global variable in the single instance codeunit. You then call the single instance codeunit to get a reference to the other one.
In this way the other codeunit becomes persistent and will exist until you CLEAR() it's variable in the single instance codeunit.
BTW: This works because codeunits are actually handles (with reference counting) unlike other Navision objects which act like C structures.Robert de Bath
TVision Technology Ltd0
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