I have the following trigger on a blackhole table, that intercepts inserts and passes them on to other tables.
In order to speed things up I want to calculate an increasing value and passes that in my inserts.
DELIMITER $$
CREATE TRIGGER ai_blackhole_each AFTER INSERT ON `test.blackhole` FOR EACH ROW
BEGIN
DECLARE calculated_id INTEGER;
SET calculated_id = calc_id_for_previous_insert + 1;
INSERT INTO example VALUES(new.field1, new.field2, calculated_id, ..);
END$$
DELIMITER ;
Can I have a static variable inside a trigger that keeps its value between firings?
Or is there a trick to achieve something like that efficiently?
Place an intermittent value in a MEMORY table starting at 0
Here is what I got when I pasted this into MySQL
You can start the initial value in the test.blackholecounter table with some other number or change the order when the increment happens in the trigger.
Give it a Try !!!