It makes sense that a name-based lookup might be a little slower with multiple matching rules than one that is an integer index. However, I have a hard-time believing that this explains a 3% (or 5-7% in my project) relative cost for each row when we are talking about an average number of 10-15 [column] entries in the data set. It is worth clarifying in the prior statement I am referring to the number of columns that this "dereferencing" occurs against, and not the number of records in the data set. These costs above are in the context that these lookups are occuring once for every row. So they could be occuring a lot.
idr.GetOrdinal(name) // Name based lookup
idr[name] // Name-based lookup
idr.GetValue(index) // Ordinal-based lookup
Is there actually additional communication with the database needed to do name-based field lookups? What makes them so much slower?
I also noticed for getting column names the following code:
List<string> columnList = new List<string>();
for (int i = 0; i < idr.FieldCount; i++)
{
columnList.Add(idr.GetName(i));
}
return columnList;
is much faster than an equivalent version using GetSchemaTable, I'm guessing it's for the same reasons.
This question arises in spirit from: Ordinal-Based Lookups vs. Name Based Lookups