Bug #43802 NDBAPI : NdbApi created bit field null bits incorrectly handled
Submitted: 23 Mar 2009 11:53 Modified: 30 Mar 2009 17:15
Reporter: Frazer Clement Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:6.3+ OS:Any
Assigned to: Frazer Clement CPU Architecture:Any

[23 Mar 2009 11:53] Frazer Clement
Description:
The NdbRecord API supports 2 application-memory formats for BIT columns :
 - 'NdbApi' format - with data at a byte offset and null bits at a byte+bit offset
 - 'MySQLD' format - with null bit and 'fractional' data bits at the null byte+bit offset and full bytes of data at a byte offset

MySQLD format is used for all BIT columns read/written by the MySQLD server.  NdbApi programs can use either.

With NdbApi format, the current record reading code *always* clears the column's null bit when the column has data - *even* if the column is not nullable.  If the supplied null byte and bit offsets correspond to some valid bit in the record, then that bit can be trampled.

How to repeat:
Run testNdbApi -n NdbRecordPkAmbiguity T15

At some iteration, column 1, a VARCHAR(100) is set to Null.  It's null bit in the default record is in position 0,0.  Column 33 is not nullable, and has a default null bit + byte offset of 0,0.  When its data is written to the record, it clears the null bit at position 0,0 which clears the nullness of column 1.

Note that the MySQLD format is not affected as it always has distinct nullbit + byte column offsets.

Suggested fix:
Have NdbApi bitField handling code only clear nullbits if the column is nullable.

Consider setting default record null bit and byte offsets to maximum value rather than more-likely-to-be-valid 0,0.
[23 Mar 2009 12:17] Frazer Clement
Introduced in 6.3.
[23 Mar 2009 12:55] 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/70047

2913 Frazer Clement	2009-03-23
      Bug#43802 : NdbApi created bit field null bits incorrectly handled.
      modified:
        storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
        storage/ndb/src/ndbapi/NdbReceiver.cpp
[23 Mar 2009 13:00] Bugs System
Pushed into 5.1.32-ndb-7.0.5 (revid:frazer@mysql.com-20090323125739-c6bun3b6o8vv85tk) (version source revid:frazer@mysql.com-20090323125739-c6bun3b6o8vv85tk) (merge vers: 5.1.32-ndb-7.0.5) (pib:6)
[23 Mar 2009 13:01] Bugs System
Pushed into 5.1.32-ndb-6.3.24 (revid:frazer@mysql.com-20090323125455-74x2iw4vy0vopak9) (version source revid:frazer@mysql.com-20090323125455-74x2iw4vy0vopak9) (merge vers: 5.1.32-ndb-6.3.24) (pib:6)
[30 Mar 2009 17:15] Jon Stephens
Documented bugfix in the NDB-6.3.24 and 7.0.5 changelogs as follows:

        BIT columns created using the native NDB API format that were
        not created as nullable could still sometimes be overwritten, or
        cause other columns to be overwritten.

        This issue did not effect tables having BIT columns created
        using the mysqld format (always used by MySQL Cluster SQL
        nodes).