MySQL Forums
Forum List  »  NDB clusters

MySQL Cluster after/before update trigger: trigger starts to return null for NEW.column
Posted by: Jarrod van den Heuvel
Date: May 16, 2014 04:38AM

Basic run down:
Primary table 'testingtable' has a trigger 'testingtable_afterupdate' after update.
This trigger is into insert into a temporary table 'temphistorysqlstestingtable' (have it as temporary and normal (innodb, nbd) no difference) the transaction id of the row that was updated if there were any changes.

The 'templog' table is just for output purposes to see the results

What happens:
After creating the primary table, inserting a row and performing multiple updates on that row, templog shows correct response each time 'testingtable-first:1..' with the correct datetime and transaction id of the row updated

Then create the temp table and perform 1 update, and templog shows correct again with 'testingtable-first:0..' and extra row 'testingtable-second:0..' showing that it has inserted into the temp table because it now exists.
Perform a second update and all the values that are to be referenced are not that of the row updated.
templog now shows that the updateddate is 0000-00-00 00:00:00 and the transaction id of 0, with the other columns being null.

Now this doesn't happen if the first thing after creating the primary table is creating the temporary table. If the temp table exists before the first updates everything behaves accordingly. But if you drop the temp, perform updates, then recreate the temp, perform the 2 updates the second one is incorrect again.

I have tested the case with the primary table 'testingtable' as innodb table and NEW/OLD return the correct values of the row updated.

If executing the how to repeat steps, if the primary table is ndbcluster templog has 5 rows in it VS innodb 6 rows (correct) as there are 2 updates where the temp table doesn't exist and 2 where it does.

How to repeat:
DROP TRIGGER IF EXISTS testingtable_afterupdate;
DROP TEMPORARY TABLE IF EXISTS temphistorysqlstestingtable;
DROP TABLE IF EXISTS testingtable;
DROP TABLE IF EXISTS templog;

CREATE TABLE templog (
templogtransactionid bigint NOT NULL AUTO_INCREMENT,
output LONGTEXT,
PRIMARY KEY (templogtransactionid)
);

CREATE TABLE testingtable (
testingtabletransactionid bigint NOT NULL AUTO_INCREMENT,
updateddate datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
historydate datetime,
updateduser varchar(50),
currenthistoryflag varchar(10) NOT NULL DEFAULT 'CURRENT',
testcolumn VARCHAR(50),
PRIMARY KEY (testingtabletransactionid)
) engine =
-- innodb
ndbcluster
;

DELIMITER ///
CREATE TRIGGER testingtable_afterupdate AFTER UPDATE ON testingtable
FOR EACH ROW
BEGIN
DECLARE no_such_table TINYINT(1) DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42S02' SET no_such_table := 1;
DO (SELECT NULL FROM temphistorysqlstestingtable LIMIT 0);

INSERT INTO templog(output) values (concat('testingtable', '-first:', no_such_table, '-', NEW.currenthistoryflag, '-', NEW.updateddate, '-', OLD.updateddate));

IF no_such_table = 0 AND NEW.currenthistoryflag <> 'HISTORY' AND NEW.updateddate <> '0000-00-00 00:00:00'
AND (IFNULL(NEW.testingtabletransactionid, '') <> IFNULL(OLD.testingtabletransactionid,'') OR IFNULL(NEW.updateddate, '') <> IFNULL(OLD.updateddate,'') OR IFNULL(NEW.historydate, '') <> IFNULL(OLD.historydate,'') OR IFNULL(NEW.updateduser, '') <> IFNULL(OLD.updateduser,'') OR IFNULL(NEW.currenthistoryflag, '') <> IFNULL(OLD.currenthistoryflag,'') OR IFNULL(NEW.testcolumn, '') <> IFNULL(OLD.testcolumn,''))
THEN
INSERT INTO templog(output) values (concat('testingtable', '-second:', no_such_table, '-', NEW.currenthistoryflag, '-', NEW.updateddate, '-', OLD.updateddate));

INSERT INTO temphistorysqlstestingtable (transactionids) VALUES (
NEW.testingtabletransactionid
);

END IF;
END; ///
DELIMITER ;

INSERT INTO testingtable (testcolumn) VALUES ('test');

UPDATE testingtable SET testcolumn = 'test2' WHERE testcolumn='test';
UPDATE testingtable SET testcolumn = 'test' WHERE testcolumn='test2';

CREATE TEMPORARY TABLE temphistorysqlstestingtable (transactionids BIGINT);

UPDATE testingtable SET testcolumn = 'test2' WHERE testcolumn='test';

SELECT * FROM templog order by templogtransactionid desc limit 50;

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL Cluster after/before update trigger: trigger starts to return null for NEW.column
2208
May 16, 2014 04:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.