Bug #33379 valgrind error in parts/partition_bit_myisam
Submitted: 19 Dec 2007 19:10 Modified: 28 Mar 2008 15:07
Reporter: Mattias Jonsson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any

[19 Dec 2007 19:10] Mattias Jonsson
Description:
test case partition_bit_myisam.test in suite parts fails with valgrind errors

How to repeat:
compile with valgrind
./mtr --valgrind --suite=parts partition_bit_myisam

Suggested fix:
--- 1.424/sql/field.cc	2007-12-05 23:31:15 +01:00
+++ edited/sql/field.cc	2007-12-19 19:59:40 +01:00
@@ -8774,7 +8774,7 @@
   : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
           unireg_check_arg, field_name_arg),
     bit_ptr(bit_ptr_arg), bit_ofs(bit_ofs_arg), bit_len(len_arg & 7),
-    bytes_in_rec(len_arg / 8)
+    bytes_in_rec((len_arg + 7) / 8)
 {
   flags|= UNSIGNED_FLAG;
   /*

I.e. field is created with wrong number of bytes in record, affects field->pack_lenght_in_rec() function that is used in partitioning.
[19 Dec 2007 20:11] Mattias Jonsson
suggested fix is wrong!

better to fix by changing pack_length_in_rec() function instead.
[1 Feb 2008 9:58] Mattias Jonsson
As Kristian Nielsen proposed:
The problem lies in Field::hash (which Field_bit is using).
I will try to implement the Field_bit::hash function using my_charset_bin.coll->hash_sort() with a correct buffer.
[4 Feb 2008 11:28] 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/41633

ChangeSet@1.2516, 2008-02-04 12:28:42+01:00, mattiasj@client-10-129-10-147.upp.off.mysql.com +4 -0
  Bug#33379: valgrind error in parts/partition_bit_myisam
  
  Problem was that Field_bit used Field::hash() function that did not
  know about using null-byte for storing bits.
  Resulting in wrong length, which was caught by valgrind.
  
  Soluiton: created a Field_bit::hash() that uses Field_bit::val_int()
  and my_charset_bin-collation function hash_sort.
[4 Feb 2008 15:32] Mattias Jonsson
As Kristian commented, the previous patch was endianess dependent, I will remake it endian independent, using mi_intNstore into a local buffer.
[7 Feb 2008 9:13] 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/41855

ChangeSet@1.2516, 2008-02-07 10:12:56+01:00, mattiasj@witty.ndb.mysql.com +4 -0
  Bug#33379: valgrind error in parts/partition_bit_myisam
  
  Problem was that Field_bit used Field::hash() function that did not
  know about using null-byte for storing bits.
  Resulting in wrong length, which was caught by valgrind.
  
  Solution: created a Field_bit::hash() that uses Field_bit::val_int()
  and my_charset_bin-collation function hash_sort.
  Also use the store function for platform independs
[7 Feb 2008 11:11] Mattias Jonsson
Discussed with Mikael, and we decided to change the switch/case to use the mi_int8store directly. new patch will be committed soon
[7 Feb 2008 11:28] 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/41860

ChangeSet@1.2516, 2008-02-07 12:28:38+01:00, mattiasj@witty.local +4 -0
  Bug#33379: valgrind error in parts/partition_bit_myisam
  
  Problem was that Field_bit used Field::hash() function that did not
  know about using null-byte for storing bits.
  Resulting in wrong length, which was caught by valgrind.
  
  Solution: created a Field_bit::hash() that uses Field_bit::val_int()
  and my_charset_bin-collation function hash_sort.
  Also use the store function for platform independs
[7 Feb 2008 18:45] Mattias Jonsson
Pushed into mysql-6.0-engines and mysql-5.1-engines
[27 Mar 2008 11:21] Bugs System
Pushed into 5.1.24-rc
[27 Mar 2008 17:53] Bugs System
Pushed into 6.0.5-alpha
[28 Mar 2008 9:41] Jon Stephens
There don't appear to be any user-visible changes here; closed bug without taking further action.
[28 Mar 2008 9:51] Kristian Nielsen
I think the user-visible change here is that before this fix, PARTITION BY KEY on
bitfields did not work correctly. I think rows could end up in the wrong
partition, causing wrong results to be returned from queries or other similar
problems.

We do not have a testcase for this though.

Still, might be good to document that this bug fixes potential problems with
PARTITION BY KEY on bitfield columns.
[28 Mar 2008 9:53] Jon Stephens
Setting this back to Documenting status per developer comment above.
[28 Mar 2008 15:07] Jon Stephens
Documented bugfix as follows in the 5.1.24 and 6.0.5 changelogs:

        A table defined using PARTITION BY KEY and having a BIT column referenced 
        in the partitioning key did not behave correctly; some rows could be 
        inserted into the wrong partition, causing wrong results to be returned 
        from queries.
[2 Apr 2008 16:03] Jon Stephens
Also noted fix in the 5.1.23-ndb-6.3.11 changelog.