Creative uses for the blackhole engine
According to the documentation:
http://dev.mysql.com/doc/refman/5.0/en/blackhole-storage-engine.htmlthe 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.
Wha开发者_JS百科t other creative uses for this engine can you come up with?
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.
Seems to be a great "mock" database for program-testing purposes.
I often use Python's internal SQLite database for such things, but having a MySQL-specific mock database would be nice; thanks for sharing.
(A unit-test could, as a last step, drop the test tables; etc. But the "blackhole" engine would obviate that step.)
精彩评论