Bug #42238 NDBAPI : NdbRecord insert permits key column value ambiguity
Submitted: 21 Jan 2009 11:54 Modified: 17 Mar 2009 20:05
Reporter: Frazer Clement Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:6.2+ OS:Any
Assigned to: Frazer Clement CPU Architecture:Any

[21 Jan 2009 11:54] Frazer Clement
Description:
The NdbTransaction::insertTuple() method takes both a key NdbRecord and row pair, and an attribute NdbRecord and row pair.

However there is no mechanism to ensure that the primary key column values supplied in the key and attribute rows are the same.

If a caller supplied differing values, the data stored in the cluster could be internally inconsistent.

How to repeat:
Write NDBAPI program to insert, with different values supplied in key and attribute rows.

Monitor signals sent and/or any inconsistencies when reading data by primary key, or ordered index.

Suggested fix:
Primary key values supplied in the key row should override any differing values supplied in the attribute row.
[13 Mar 2009 1:10] 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/69087

2869 Frazer Clement	2009-03-13
      Bug#42238 NDBAPI : NdbRecord insert permits key column value ambiguity
      
      The NdbRecord insert/write API allows two separate values to be supplied
      for primary key columns - one in the key row and the other in the
      attr row.  These are sent separately as KeyInfo and AttrInfo to the kernel.
      
      This fix modifies NDBAPI to ensure that both KeyInfo and AttrInfo contain
      primary key column values from the key row.
      
      A new testcase is added to check that when the key and attribute records
      differ in PK column values, the data inserted is correct when read back
      (from TUP).
      modified:
        storage/ndb/src/ndbapi/NdbOperationExec.cpp
        storage/ndb/test/ndbapi/testNdbApi.cpp
        storage/ndb/test/run-test/daily-basic-tests.txt
[13 Mar 2009 8:54] Jonas Oreland
comment: i scanned the patch and found the following comment
"Can't change key with update"

This is not true!
If you use case insensitive collation for primary key
it's a perfectly valid operation to do "update set key='A' where key = 'a'"

don't if code prevents this...or if comment was just wrong...
---
please generate new patch (with potentially changed code)
[13 Mar 2009 16:20] Frazer Clement
New proposed patch

Attachment: ambiguity_3.patch (text/x-patch), 24.36 KiB.

[13 Mar 2009 16:24] Frazer Clement
New version of patch : 
  - Removes previous patch's NDBAPI checks that PK column is not updated, to allow collation-safe PK updates
  - Modifies scanTakeover update op code to take PK column vals from attr row so that scanTakeover update can also do collation-safe pk updates
  - Adds testcode to testNdbApi to check that PK cols can be updated to contain the same values (NdbRecordPkUpdate) via PK and scan takeover, but scan takeover cannot change the pk value in this way- kernel generates error.
  - Adds testcode to testNdbApi to check that PK cols with suitable (for example case insensitive) collation can modify pk col vals via update operation.
[17 Mar 2009 0:52] 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/69372

2879 Frazer Clement	2009-03-17
      Bug#42238 NDBAPI : NdbRecord insert permits key column value ambiguity
      
      The NdbRecord Insert Api allows key columns to be specified in the key record
      and in the attribute record.  It is important that only one key column value 
      for each key column is sent to the kernel.
      This patch ensures this by taking key column values from the key record for
      insert and write operations.
      For scan takeover update operations, key column values are taken from the
      attribute record.
      The testNdbApi testcase is extended with 3 new testcases : 
       - NdbRecordPKAmbiguity
         Verifies that rows inserted/written with divergent key values in the
         key and attribute records contain the correct key values
       - NdbRecordPKUpdate
         Verifies that PK columns can be updated to the same values they contain
         via PK and scan takeover update operations.
       - NdbRecordCICharPKUpdate
         Verifies that a PK column with a case-insensitive VARCHAR column can
         be updated to contain distinct but collation-equal values using PK
         and scan takeover update operations.
      
      These testcases are added to daily-basic-tests.
      modified:
        storage/ndb/src/ndbapi/NdbOperationExec.cpp
        storage/ndb/test/ndbapi/testNdbApi.cpp
        storage/ndb/test/run-test/daily-basic-tests.txt
[17 Mar 2009 1:21] Bugs System
Pushed into 5.1.32-ndb-7.0.4 (revid:frazer@mysql.com-20090317011721-fgtlp5cry4rynf6w) (version source revid:frazer@mysql.com-20090317011721-fgtlp5cry4rynf6w) (merge vers: 5.1.32-ndb-7.0.4) (pib:6)
[17 Mar 2009 1:22] Bugs System
Pushed into 5.1.32-ndb-6.3.24 (revid:frazer@mysql.com-20090317005830-ob42p4wofpkax1iq) (version source revid:frazer@mysql.com-20090317005830-ob42p4wofpkax1iq) (merge vers: 5.1.32-ndb-6.3.24) (pib:6)
[17 Mar 2009 1:23] Bugs System
Pushed into 5.1.32-ndb-6.2.18 (revid:frazer@mysql.com-20090317005141-3rtsp2z5hriekkwk) (version source revid:frazer@mysql.com-20090317005141-3rtsp2z5hriekkwk) (merge vers: 5.1.32-ndb-6.2.18) (pib:6)
[17 Mar 2009 20:05] Jon Stephens
Documented bugfix in the NDB-6.2.18, 6.3.24, and 7.0.4 changelogs as follows:

        When performing insert or write operations, NdbRecord allows key
        columns to be specified in both the key record and in the
        attribute record. Only one key column value for each key column
        should be sent to the NDB kernel, but this was not guaranteed.
        This is now ensured as follows: For insert and write operations,
        key column values are taken from the key record; for scan
        takeover update operations, key column values are taken from the
        attribute record.
[23 Mar 2009 18:07] 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/70099

2915 Frazer Clement	2009-03-23
      Fix testBlobs unique index write with correction to fix for bug#42238 (NdbRecord Pk ambiguity)
      modified:
        storage/ndb/src/ndbapi/NdbOperationExec.cpp
[23 Mar 2009 18:29] Bugs System
Pushed into 5.1.32-ndb-7.0.5 (revid:frazer@mysql.com-20090323182758-61xap301hj7zno3q) (version source revid:frazer@mysql.com-20090323182758-61xap301hj7zno3q) (merge vers: 5.1.32-ndb-7.0.5) (pib:6)
[23 Mar 2009 18:30] Bugs System
Pushed into 5.1.32-ndb-6.3.24 (revid:frazer@mysql.com-20090323180633-9qlwuup0nmv40ltd) (version source revid:frazer@mysql.com-20090323180633-9qlwuup0nmv40ltd) (merge vers: 5.1.32-ndb-6.3.24) (pib:6)
[25 Mar 2009 18: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/70415

2890 Frazer Clement	2009-03-25
      Fix testBlobs unique index write with correction to fix for bug#42238 (NdbRecord Pk Ambiguity) - apply to 6.2
      modified:
        storage/ndb/src/ndbapi/NdbOperationExec.cpp
[25 Mar 2009 19:00] Bugs System
Pushed into 5.1.32-ndb-7.0.5 (revid:frazer@mysql.com-20090325185815-seenegn5g7ndv7b0) (version source revid:frazer@mysql.com-20090325185815-seenegn5g7ndv7b0) (merge vers: 5.1.32-ndb-7.0.5) (pib:6)
[25 Mar 2009 19:01] Bugs System
Pushed into 5.1.32-ndb-6.3.24 (revid:frazer@mysql.com-20090325185649-6ll45rue69p4a38j) (version source revid:frazer@mysql.com-20090325185649-6ll45rue69p4a38j) (merge vers: 5.1.32-ndb-6.3.24) (pib:6)
[25 Mar 2009 19:06] Bugs System
Pushed into 5.1.32-ndb-6.2.18 (revid:frazer@mysql.com-20090325185439-1fzzwjettta0ea1t) (version source revid:frazer@mysql.com-20090325185439-1fzzwjettta0ea1t) (merge vers: 5.1.32-ndb-6.2.18) (pib:6)