Hi
I have read topic
http://www.mibuso.com/forum/viewtopic.php?t=11112
Is the conclusion from this to use the new functions where appropriate in all new projects, regardless of DB used in production system?
For example a quote from help on topic Findfirst:
This function should be used instead of FIND('-') when you only need the first record.
Any input on this will be appreciated.
Thomas
Comments
In native database I think has the same performance has FIND('-')
The problem is to develop an add-on and you want to convert to 3.70, these functions won't work in that version.
When I made Navision customizations where the client supports the new functions, I always use it, even if the customer is using native DB, because the customer might some day to upgrade to SQL.
Freelance Dynamics AX
Blog : http://axnmaia.wordpress.com/
RIS Plus, LLC
If you want to do a repeat/until you can better do a FIND('-') because you'll need al the data anyway.
I only use FINDFIRST and FINDLAST when I don;t need all the records.
Or have I misunderstood?
Findset:
Does this mean one have to keep in mind whether >500 Records are to be retrieved or not?
What type of transaction will read more than 500 records without being a report?
if you define a report on the customer table the SQL statement is
Batch processing? These are performance nightmares anyways.
These new functions are implemented to speedup posting transactions I think.
The limit how much records are read through FINDSET can be changed in database settings - you cannot assume if it is 500 or just 10... :-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I still cannot see any logic in it.
Has anybody succesfully replaced FIND('-') by FINDSET and gained performance?
Code Optimizations – FINDSET (4.00 SP1)
Syntax: [Ok :=] FINDSET([ForUpdate] [, UpdateKey])
ForUpdate – Set to FALSE if you do not intend to modify records. Set to TRUE if you intend to modify records. If TRUE, then a Locktable is performed prior to records being read.
UpdateKey – ForUpdate must be TRUE, set if you intend to update the current key
Optimize loops explicit code
Reuse of cursors
Database property ‘Record Set’. Sets the amount of records retrieved in the default record set
Note: Dataset can only be retrieved in Ascending Order
FINDSET(FALSE,FALSE) Readonly
Firehose, No server Cursor used, Record Set is cached (No Fetch), Less Server round-trips
FINDSET(TRUE,FALSE) Update Non-Key Field
Dynamic Cursor
FINDSET(TRUE,TRUE) Update key field
Fetch, fetch (single row)
If the limit is reached, next 500 is loaded automatically when you reach end of the first set... :-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Retrieving large sets
When you use FINDSET without any parameters it functions as a firehose and fetches
around 500 records. If you want to retrieve more than 500 records, you can still use
the FIND('-') function. Alternatively, you can use FINDSET(True).
If you need less than 500 records, use LOCKTABLE and then FINDSET.
In summary, there are three simple rules that you should follow when using FIND
statements:
· If you are writing a NEXT statement, always use FINDSET.
· Always tell the server when you want to update some records. Call LOCKTABLE first
and then use FINDSET to modifying the records.
· Your code should match the size of the record set that you want to retrieve.
3 rules:
If you want to loop, use FINDSET. This returns a set of records.
If you need to have one record, use FINDFIRST or FINDLAST. This returns one record only.
If you need to know whether records exist in your filter, use ISEMPTY. This returns a bit (Yes/No) and is all you really need to know if there are records in the filter.
RIS Plus, LLC
as opposed to
I can see why that could potentially increase performance, but on the other hand I can also see how it could potentially decrease it...
I suppose the right solution depends on how often you could expect the (filtered) table to be empty, but does anybody have a non-guessing approach to this?
Senior NAV Developer
Elbek & Vejrup
Just use the FINDSET.
Using the ISEMPTY will trigger 2 database calls:
- SELECT TOP NULL ...
- SELECT TOP 500 * FROM ...
When using only the FINDSET, it triggers 1 database call. I agree, it's a heavier one as the ISEMPTY, but when it returns no records, it doesn't really matter.
Just make sure your indexes are ok.
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
RIS Plus, LLC
...
Everybody on-line.
...
Looking good!
I mean...I still have to use 2 variables and modifying the one I am not looping through or I can "do whatever I want without worries?"
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
by the way you can it all depends on what is your purpose
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
The new find functions behave in exactly the same manner as the old ones in this regard. The parameters for FINDSET are only used for performance optimization on the SQL Server.
From a NAV standpoint the parameters are irrelevant - the code will work either way.
Senior NAV Developer
Elbek & Vejrup
I also ask myself why not to use COUNT.
Now, I doubt in what is the best resolution. the best way to test this is to create multiple functions and screen it with the client monitor. It only takes a few minutes.
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
Do not write code such as:
NEXT should not follow FINDFIRST because FINDFIRST does not establish a set operation against SQL Server - it is intended for retrieval of the first record only. The NEXT will then need to create the set which may be expensive because of the WHERE clause it will need to generate. Always use FINDSET or FIND('-') with NEXT.
Note:
From 5.0 onwards you can detect where there is code executing like this by setting the value of the [diagnostics] field in the [$ndo$dbproperty] table of the database:
Set to value 16384 - writes a SQL Error parameter to the Client Monitor if running,
Set to value 81920 - generates an ERROR, aborting execution.
Message: "Detected a NEXT function call on a record without a matching FIND/FINDSET call."
This posting is provided "AS IS" with no warranties, and confers no rights.
Sorry! #-o
It's what the topic is about... :oops:
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Is there some documentation available about functions like this?? This is very useful.
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
RIS Plus, LLC
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
This posting is provided "AS IS" with no warranties, and confers no rights.
Anyway, I will try this out.
thanks for the info!
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog