Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creative uses for the blackhole engine

Tags:

mysql

According to the documentation:
http://dev.mysql.com/doc/refman/5.0/en/blackhole-storage-engine.html

the blackhole storage engine can be used for things like diagnostics and offloading the binary log to a different machine, without having to store the database on that machine.

What other creative uses for this engine can you come up with?

like image 732
Johan Avatar asked May 01 '11 21:05

Johan


1 Answers

Found one a using a trigger:

If you have a complicated series of inserts or updates that needs to happen in a transaction, you can do these in application code, or

You can create one 'big' blackhole table with enough rows to hold all the values.

And create a trigger like:

DELIMITER $$

CREATE TRIGGER ai_bh_table_each AFTER INSERT ON bh_table FOR EACH ROW
BEGIN
  DECLARE lastid1 integer;

  INSERT INTO table1 VALUES (null, new.field1, new.field2);
  SELECT LAST_INSERT_ID() INTO lastid1;
  INSERT INTO table2 VALUES (null, new.field3, lastid1);
  ....  
END$$

DELIMITER ;

If you include error checking code you can even simulate transactions on engines that don't support it, like MyISAM.

like image 51
Johan Avatar answered Sep 30 '22 12:09

Johan