Someone asked me what is the need to have an exist() method when we have a find() method already declared on a table? Logically, exist() checks if a record with a given key exists and find also nearly does the same thing, it fetches the actual record? So why the need for an exist() method? Well, the answer is performance.
The find() method always returns a buffer of the table on which it is called whereas if you look at the syntax of the exist() method, it only returns the RecId. Selecting only a single field versus the entire table takes less time.
On my test machine, calling the exist() method on CustTable with 2000 records finished in 0.0136 milliseconds whereas find() took 0.1388 milliseconds. The rule of thumb is, querying on any indexed field will always be faster than a non-indexed field. So, even if the exist() method on CustTable was selecting AccountNum or PartyId, it would return in 0.0136 m/s only.
Performance degrades only when you mix fields, so selecting (RecId, Name) will slow down to 0.1388 and that is as good as the find() method.
So the bottom line is that exist() methods exist because there are faster than find() methods when large number of records are being queried and helps improve performance.
Aucun commentaire:
Enregistrer un commentaire