Trigger generating strange values in auto increment column
Hi,
I have a slave database configured. I have the following table:
CREATE TABLE `changes` (
`table` varchar(30) NOT NULL,
`action` varchar(15) NOT NULL,
`row_id` int(11) NOT NULL,
`change_id` bigint(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`change_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
and a trigger:
delimiter //
create trigger stars_update after update on stars
for each row
begin
if OLD.name <> NEW.name then
insert into changes (`table`, `action`, row_id) values ('stars', 'update', NEW.star_id);
end if;
end;
//
delimiter ;
So whenever record in stars table is updated by replication I should have new record inserted into changes table. It works, but the trigger is generating strange values for changes.change_id column. After first trigger run I got:
mysql> select * From changes;
+-------+--------+--------+-----------+
| table | action | row_id | change_id |
+-------+--------+--------+-----------+
| stars | update | 3711 | 563113 |
+-------+--------+--------+-----------+
1 row in set (0.00 sec)
When I execute truncate changes and alter table changes auto_increment = 1, next insert looks like this:
mysql> select * From changes;
+-------+--------+--------+-----------+
| table | action | row_id | change_id |
+-------+--------+--------+-----------+
| stars | update | 3711 | 563114 |
+-------+--------+--------+-----------+
1 row in set (0.00 sec)
What's more, when I do manual inserts, auto increment values are generated properly starting from 1 (after truncation). It seems like the trigger is generating it's own auto increment values. Restaring MySQL doesn't help.
Another thing is, when I do manual insert to changes table, another trigger execution gets duplicate-key error for changes_id column.
I'm using mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) using readline 6.1.
I would appreciate any help or hints.
Subject
Views
Written By
Posted
Trigger generating strange values in auto increment column
3308
May 06, 2011 02:42AM
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.