Bug #37239 MySqlReader GetOrdinal performance changes break existing functionality
Submitted: 6 Jun 2008 7:26 Modified: 8 Jul 2008 16:43
Reporter: Christos Pavlides Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.3.0.0 OS:Any
Assigned to: CPU Architecture:Any

[6 Jun 2008 7:26] Christos Pavlides
Description:
Hi guys,
The new GetOrdinal performance improvements are great and I have to say it again all these performance improvements that are happening lately are very welcome and I hope we will see more of them soon.

But (there is always a but with me..) the latest changes break existing functionality. What is happening is if you have duplicate column names in your resultset then the connector will try to add the two columns in the fieldHashCS and fieldHashCI hashtables with the same name and it will throw an expection because of the duplicate key. 

How to repeat:
In my case I have a procedure that returns the result of a select statement which contains a few joins. Two of the tables are joined with the same lookup table, therefore by default (if I do not use aliases) the column names of both those joins will be the same. MySql does not really care and when I execute the SP it will return the duplicate column names. 
This can be easily repeated by trying to execute any query using the datareader
which has two duplicate column names such as:
SELECT a.a1, a.a1 FROM Test a;

Suggested fix:
I understand that this presents a problem to the GetOrdinal function but it was "working" without throwing an exception up to now (and I never use the GetOrdinal anyway) therefore I believe this change breaks the existing functionality.
Of course the easy fix is to alias all my columns in order to give them all unique names, but an easier fix will be to change the code to check if there is another column with the same name and give the new column a suffix such as _1, _2, _3 etc.
If this change is implemented and well documented then I believe it offer the benefit of not breaking existing applications that might have duplicate names in their resultsets and also it will allow the user to access these duplicate columns that were not accessible before (the previous functionality returned the first column found)
[6 Jun 2008 15:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/47541
[6 Jun 2008 15:31] Reggie Burnett
Fixed in 5.2.3 and higher. 

We fixed it by not adding the column names to the hashes if it already exists.  At first glance this seems to be wrong as these column names will not be retrieved in a fast way but then you realize that with multiple columns of the same name you can't retrieve them by name anyway.  The user will be forced to retrieve the column value by ordinal only.
[8 Jul 2008 16:43] Tony Bedford
An entry has been added to the 5.2.3 Changelog:

MySqlReader.GetOrdinal() performance enhancements break existing functionality.
[19 Aug 2008 15:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/51977
[2 Sep 2008 14:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/53072
[24 Oct 2008 4:42] Valeriy Kravchuk
Bug #40033 was marked as a duplicate of this one based on bug reporter's comment.