Performance of accessing dataSet fields using field names instead of indexes

Is performance negligible?

For example,

myQuery.FieldbyName("MyField").AsString; myQuery.Fields[0].AsString; 

Cases: A table with a decent number of fields, say> 50 fields

Access to large result sets, say> 100,000 rows

Is the utility for rights to field names to reduce performance?

+7
source share
3 answers

Here's an interesting post by FranΓ§ois Gaillard on FieldByName's Performance Issues .

+5
source

Performance cannot be negligible, depending on how often you access the field by name. If you use it for each field and each row, you may notice a decrease in performance (see, for example, http://www.delphifeeds.com/go/s/74559 ). To improve readability, you can improve performance:

  • Use the syntax ['FieldName'] or FieldByName () only once and store the field reference in a variable.
  • Use static ad , right-click the dataset, select Field Editor and add the required fields. It will declare a suitable TField descendant and allow you to assign a name.

In addition, AsXXXXX calls may be slower than using the native Value property for TField descendants.

+3
source

I found that FieldByName is noticeably more noticeable.

I usually access the database through an intermediate layer that accesses entire records from the same table many times. When creating this layer, I assign the index of each field to a variable. Then I use the variables for later access, so that I can still read the code.

 ADODataSet.CommandText := 'select * from [TABLE] where 1 = 0'; //table layout ADODataSet.Open; ADODataSet.GetFieldNames(List); varMyField := List.IndexOf('MyField'); 
+1
source

All Articles