Hi
Could anyone explain the differences (mainly performance) in using
FINDSET, FINDFIRST and FIND('-') ? I know that there are some (especially on SQL) but what are the "guidelines"? Code examples would be great:-)
FIND('-'): don't use this anymore, it really has not purpose anymore.
FINDSET: retrieves a set of records
FINDFIRST: retrieves only one record, the first one within the filter, sorted ascendingly
FINDLAST: retrieves only one record, the last one within the filter, sorted ascendingly
If you want to know if records exist within a certain filter, use ISEMPTY.
Check out the C/SIDE reference guide for more information, and code samples. If you need real life code samples, check out the posting codeunits in standard NAV.
One difference between FIND('-') and FINDSET(TRUE) is when the transaction begins. With FIND('-') the transaction begins when the call to update the database (INSERT, MODIFY, DELETE) is made. With FINDSET(TRUE) the transaction begins with the FINDSET command.
I might also add that findset, findfirst, findlast are more typically used if you're using SQL database. This is implemented to enhance performance.
If you're using C/SIDE, find('-') will work fine.
Some advice : ALWAYS use FINDSET,FINDFIRST,FINDLAST. Even if you work on a Navision-DB. At least if the customer decides to convert to SQL, this is already ok.
Regards,Alain Krikilion No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Nice, but in the very bottom you have an Wrong/Correct code. In the Correct section you have this statement:
Rec2.GET(Rec1.PrimaryKey);
Wouldn't it be just as good and even faster to simply:
Rec2 := Rec1;
Is there any reason to retrieve it from the db again?
[quote="pdjNice, but in the very bottom you have an Wrong/Correct code. In the Correct section you have this statement:
Rec2.GET(Rec1.PrimaryKey);
Wouldn't it be just as good and even faster to simply:
Rec2 := Rec1;
Is there any reason to retrieve it from the db again?[/quote]
The direct assignment Rec2 := Rec1; is also fine; maybe even better as you save one query. I think I will change this example in the edition of the PFG
Comments
FINDSET: retrieves a set of records
FINDFIRST: retrieves only one record, the first one within the filter, sorted ascendingly
FINDLAST: retrieves only one record, the last one within the filter, sorted ascendingly
If you want to know if records exist within a certain filter, use ISEMPTY.
Check out the C/SIDE reference guide for more information, and code samples. If you need real life code samples, check out the posting codeunits in standard NAV.
RIS Plus, LLC
http://www.stryk.info/PFG_79_81.pdf
(Taken from "The NAV/SQL Performance Field Guide", ISBN: 978-3-8370-1442-6, http://www.stryk.info/fieldguide.html (c) STRYK System Improvement)
Best regards,
Jörg
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
If you're using C/SIDE, find('-') will work fine.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
Rec2.GET(Rec1.PrimaryKey);
Wouldn't it be just as good and even faster to simply:
Rec2 := Rec1;
Is there any reason to retrieve it from the db again?
Peter
No.
It's only available as book, e.g. from Amazon, etc.
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
Rec2.GET(Rec1.PrimaryKey);
Wouldn't it be just as good and even faster to simply:
Rec2 := Rec1;
Is there any reason to retrieve it from the db again?[/quote]
The direct assignment Rec2 := Rec1; is also fine; maybe even better as you save one query. I think I will change this example in the edition of the PFG
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
Is there a performance difference (assuming a correct key is chosen) between GET and FINDFIRST?
GET only works with the primary key. FINDFIRST can be used with any key.
GET : SELECT * FROM table WHERE PrimaryKey = Value
FINDFIRST : SELECT TOP 1 * FROM table WHERE PrimaryKey = Value
In this case, the TOP 1 is no necessary, so I would go for the GET.
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog