黑洞引擎的创造性用途 [英] Creative uses for the blackhole engine
问题描述
根据文档:
http://dev.mysql.com/doc/refman/5.0/zh-CN/blackhole-storage-engine.html
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?
推荐答案
使用触发器找到了一个:
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
您可以创建一个具有足够多行以容纳所有值的大" blackhole
表.
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 ;
如果包含错误检查代码,您甚至可以在不支持它的引擎(例如MyISAM)上模拟事务.
If you include error checking code you can even simulate transactions on engines that don't support it, like MyISAM.
这篇关于黑洞引擎的创造性用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!