Bug #21400 NDB API: sub_reg subtracts registers in opposite way then commented
Submitted: 1 Aug 2006 18:13 Modified: 6 Sep 2006 12:27
Reporter: Anatoly Pidruchny (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:4.1, 5.1.x, 5.0.x OS:
Assigned to: Jonas Oreland CPU Architecture:Any

[1 Aug 2006 18:13] Anatoly Pidruchny
Description:
The comment for the sub_reg function in the NdbOperation.hpp specifies:

  /**
   * Interpreted program instruction:
   * Substract RegSource1 from RegSource2 and put the result in RegDest.
   *
   * @param RegSource1   First register.
   * @param RegSource2   Second register.
   * @param RegDest      Destination register where the result will be stored.
   * @return             -1 if unsuccessful.
   */
  int   sub_reg(Uint32 RegSource1, Uint32 RegSource2, Uint32 RegDest);

In other words, logically the operation is supposed to be:
RegDest = RegSource2 - RegSource1;

In reality, it does the opposite, it subtracts RegSource2 from RegSource1. Logically, it does:
RegDest = RegSource1 - RegSource2;

How to repeat:
The test program illustrates the problem. The test program creates the table mytablename in the test_db_1 database, then inserts 10 records, then updates all the records using an interpreted program with sub_reg operation. It loads 1 into register 0, then loads 2 into register 1, then calls sub_reg(0, 1, 2) to put the result of Register 1 - Register 0 into Register 2. In reality, it puts the result of Register 0 - Register 1 into Register 2. Then the value from the register 2 is written into the ATTR2 in table mytablename and the updated value is printed. The value printed is 4294967295, or 0xFFFFFFFF; not 1, as expected.

Suggested fix:
It is OK if just the comment in the NdbOperation.hpp is changed so that it correctly describes what the operation does now. Another way is to make the operation behave as described. To do this, only one line of code has to be changed. For release 5.1.11, in the file storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp, line 2090 should be modified from:

            Int64 Tdest0= Tleft0 - Tright0;

to:

            Int64 Tdest0= Tright0 - Tleft0;
[1 Aug 2006 18:14] Anatoly Pidruchny
Test program

Attachment: sub_reg_opposite.cpp (application/octet-stream, text), 5.97 KiB.

[2 Aug 2006 11:54] MySQL Verification Team
Changing to Cluster category.
[4 Aug 2006 7:43] 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/10035

ChangeSet@1.2539, 2006-08-04 09:43:23+02:00, jonas@perch.ndb.mysql.com +1 -0
  ndb - bug#21400
    Fix docs for NdbOpertation::sub_reg
[1 Sep 2006 8:05] Jonas Oreland
pushed to 5.1.12
[1 Sep 2006 19:35] Jonas Oreland
pushed to 5.0.25
[6 Sep 2006 7:14] Jonas Oreland
pushed into 4.1.22
[6 Sep 2006 12:27] Jon Stephens
Nothing for docs here, as interpreted programs are for internal use only, and not part of the public API.