Bug #39909 Wrong comparison result with NEW and OLD keywords on update
Submitted: 7 Oct 2008 13:35 Modified: 8 Oct 2008 19:00
Reporter: Frank Hieronymi Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.67 OS:Windows (XP SP3)
Assigned to: CPU Architecture:Any

[7 Oct 2008 13:35] Frank Hieronymi
Description:
When comparing a field value's NEW and OLD value in an update trigger you sometimes get wrong results.

How to repeat:
Change the value of the field "datum" to a non NULL value -> comparison gives wrong result and no value is entered into table2. Change value back to NULL -> value is entered into table2.

/*
SQLyog Enterprise - MySQL GUI v7.02 
MySQL - 5.0.67-log : Database - test
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

/*Table structure for table `table1` */

CREATE TABLE `table1` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `datum` date default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

/*Data for the table `table1` */

insert  into `table1`(`id`,`datum`) values (1,NULL);

/*Table structure for table `table2` */

CREATE TABLE `table2` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `result` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `table2` */

/* Trigger structure for table `table1` */

DELIMITER $$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'localhost' */ /*!50003 TRIGGER `table1_after_upd_tr` AFTER UPDATE ON `table1` FOR EACH ROW BEGIN
  IF NOT (NEW.datum <=> OLD.datum) THEN
    INSERT INTO table2 VALUES(NULL,1);
  END IF;
END */$$

DELIMITER ;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
[8 Oct 2008 19:00] Sveta Smirnova
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Duplicate of bug #39423