Bug #72023 Unnecessary byte array creation in MysqlIO#unpackBinaryResultSetRow
Submitted: 12 Mar 2014 14:17 Modified: 3 Apr 2014 20:33
Reporter: Andrej Golovnin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S5 (Performance)
Version:5.1.29 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: jdbc, MysqlIO

[12 Mar 2014 14:17] Andrej Golovnin
Description:
In the method MysqlIO#unpackBinaryResultSetRow in lines 4779-4783 an array is created to hold the null bit mask. This is not really necessary and you use a for-loop to copy bytes from one byte array into other, which is not very efficient. The creation of the array and copying of the bytes can be avoided at all as the data is still available in the original Buffer object. You should just store the current position of the Buffer in the variable "nullMaskPos" and then change the position of the Buffer to point to the real data and use the method Buffer#readByte(int) with nullMaskPos as argument later to access the null bit mask.

How to repeat:
Review the code of the method MysqlIO#unpackBinaryResultSetRow in lines 4779-4783.

Suggested fix:
See attached patch.
[12 Mar 2014 14:17] Andrej Golovnin
Patch for this issue.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: MysqlIO_72023.patch (application/octet-stream, text), 1.11 KiB.

[14 Mar 2014 11:57] Filipe Silva
Hi Andrej,

Thank you for this bug report and contribution.
Verified as described, contribution accepted.
[3 Apr 2014 20:33] Daniel So
Added the following entry into the Connector/J 5.1.31 changelog:

"In the method MysqlIO.unpackBinaryResultSetRow, an array was unnecessarily created to hold the null bit mask. With this fix, Connector/J avoids the creation of the array by making use of the data that is still variable in the original buffer object."