Bug #9435 TIMESTAMP columns don't update
Submitted: 28 Mar 2005 17:42 Modified: 1 Apr 2005 18:59
Reporter: Sergio Salvatore Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:4.1.10a OS:Linux (Linux/RedHat ES 3)
Assigned to: Martin Skold CPU Architecture:Any

[28 Mar 2005 17:42] Sergio Salvatore
Description:
When using TIMESTAMP columns with NDB tables, updating columns that are not part of the primary key does not result in updating the TIMESTAMP column when it should.

How to repeat:
Given this table definition:

CREATE TABLE `testtable` (
  `number` int(10) NOT NULL default '0',
  `modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `letter` char(1) default NULL,
  PRIMARY KEY  (`number`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8

Then, inserting a row yields the expected result:

mysql> insert into testtable (number) values (1);
Query OK, 1 row affected (0.01 sec)

mysql> select * from testtable;
+--------+---------------------+--------+
| number | modified            | letter |
+--------+---------------------+--------+
|      1 | 2005-03-28 12:32:55 | NULL   |
+--------+---------------------+--------+
1 row in set (0.05 sec)

However, updating that row does not update the `modified` column as it should.

mysql> update testtable set letter = 'A' where number = 1;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from testtable;
+--------+---------------------+--------+
| number | modified            | letter |
+--------+---------------------+--------+
|      1 | 2005-03-28 12:32:55 | A      |
+--------+---------------------+--------+
1 row in set (0.05 sec)

If one were to use the same table definition with MYISAM tables, it works correctly.

However, as an aside, if one were to update the primary key, the `modified` column would update as in the following example:

mysql> update testtable set number = 2 where number = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from testtable;
+--------+---------------------+--------+
| number | modified            | letter |
+--------+---------------------+--------+
|      2 | 2005-03-28 12:36:22 | A      |
+--------+---------------------+--------+
1 row in set (0.00 sec)

Suggested fix:
TIMESTAMP columns should always update regardless of the updated column's status as a key.
[1 Apr 2005 16:00] 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/internals/23567