<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Triggers Use Case Compilation, Part I</title>
	<atom:link href="http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Sat, 13 Mar 2010 09:46:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Triggers Use Case Compilation, Part III &#124; code.openark.org</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-503</link>
		<dc:creator>Triggers Use Case Compilation, Part III &#124; code.openark.org</dc:creator>
		<pubDate>Mon, 02 Feb 2009 11:23:42 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-503</guid>
		<description>[...] Triggers Use Case Compilation, Part III [...]</description>
		<content:encoded><![CDATA[<p>[...] Triggers Use Case Compilation, Part III [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-320</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Fri, 16 Jan 2009 05:26:49 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-320</guid>
		<description>Roland,

thanks for this important correction. I&#039;ve updated the text. I have to check how I came to that conclusion.

In your sample code above, it is best if you specified ENGINE=InnoDB for those who have MyISAM as default storage engine.

When doing the above with MyISAM, no error is ever produced. Moreover, trying to ALTER tables to InnoDB still works fine, since the foreign key was silently dropped as we were using MyISAM. Will check if there&#039;s an open bug on this.

Regards,
Shlomi</description>
		<content:encoded><![CDATA[<p>Roland,</p>
<p>thanks for this important correction. I&#8217;ve updated the text. I have to check how I came to that conclusion.</p>
<p>In your sample code above, it is best if you specified ENGINE=InnoDB for those who have MyISAM as default storage engine.</p>
<p>When doing the above with MyISAM, no error is ever produced. Moreover, trying to ALTER tables to InnoDB still works fine, since the foreign key was silently dropped as we were using MyISAM. Will check if there&#8217;s an open bug on this.</p>
<p>Regards,<br />
Shlomi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Bouman</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-313</link>
		<dc:creator>Roland Bouman</dc:creator>
		<pubDate>Thu, 15 Jan 2009 23:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-313</guid>
		<description>Hi! sorry - there should be a: 

USE t2 

after the 

create database t2;

But, it works across schemata nonetheless....</description>
		<content:encoded><![CDATA[<p>Hi! sorry &#8211; there should be a: </p>
<p>USE t2 </p>
<p>after the </p>
<p>create database t2;</p>
<p>But, it works across schemata nonetheless&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Bouman</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-312</link>
		<dc:creator>Roland Bouman</dc:creator>
		<pubDate>Thu, 15 Jan 2009 23:08:38 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-312</guid>
		<description>Hi!

&quot;An interesting point, though, is exposed here: trigger-based integrity can work cross-schemata, whereas InnoDB’s foreign keys only work withing a given schema.&quot;

I don&#039;t think this is true.

mysql&gt; use t1
Database changed
mysql&gt; create table t1 (id int primary key);
Query OK, 0 rows affected (0.23 sec)

mysql&gt; create database t2;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create table t2 (id int, foreign key(id) references t1.t1 (id));
Query OK, 0 rows affected (0.11 sec)

mysql&gt; insert into t2 values (1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`t1`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))

mysql&gt; insert into t1.t1 values (1);
Query OK, 1 row affected (0.13 sec)

mysql&gt; insert into t2 values (1);
Query OK, 1 row affected (0.09 sec)

mysql&gt; delete from t1.t1;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`t1`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))


So, it works for me.</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>&#8220;An interesting point, though, is exposed here: trigger-based integrity can work cross-schemata, whereas InnoDB’s foreign keys only work withing a given schema.&#8221;</p>
<p>I don&#8217;t think this is true.</p>
<p>mysql&gt; use t1<br />
Database changed<br />
mysql&gt; create table t1 (id int primary key);<br />
Query OK, 0 rows affected (0.23 sec)</p>
<p>mysql&gt; create database t2;<br />
Query OK, 1 row affected (0.00 sec)</p>
<p>mysql&gt; create table t2 (id int, foreign key(id) references t1.t1 (id));<br />
Query OK, 0 rows affected (0.11 sec)</p>
<p>mysql&gt; insert into t2 values (1);<br />
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`t1`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))</p>
<p>mysql&gt; insert into t1.t1 values (1);<br />
Query OK, 1 row affected (0.13 sec)</p>
<p>mysql&gt; insert into t2 values (1);<br />
Query OK, 1 row affected (0.09 sec)</p>
<p>mysql&gt; delete from t1.t1;<br />
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`t1`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))</p>
<p>So, it works for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: code.openark.org &#187; Blog Archive &#187; Triggers Use Case Compilation, Part II</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-306</link>
		<dc:creator>code.openark.org &#187; Blog Archive &#187; Triggers Use Case Compilation, Part II</dc:creator>
		<pubDate>Thu, 15 Jan 2009 08:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-306</guid>
		<description>[...] Triggers Use Case Compilation, Part II [...]</description>
		<content:encoded><![CDATA[<p>[...] Triggers Use Case Compilation, Part II [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-230</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Tue, 06 Jan 2009 04:42:22 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-230</guid>
		<description>Hi Nicklas,

Can you please elaborate on this?
Regards

PS, there are more parts to this post</description>
		<content:encoded><![CDATA[<p>Hi Nicklas,</p>
<p>Can you please elaborate on this?<br />
Regards</p>
<p>PS, there are more parts to this post</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicklas Westerlund</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-229</link>
		<dc:creator>Nicklas Westerlund</dc:creator>
		<pubDate>Mon, 05 Jan 2009 19:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-229</guid>
		<description>Don&#039;t forget that you can use triggers in a replicated environment in order to mask real values in a dev environment for example as well.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t forget that you can use triggers in a replicated environment in order to mask real values in a dev environment for example as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-228</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Mon, 05 Jan 2009 18:14:24 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-228</guid>
		<description>Hi Mark,

Thanks. You are right. Using triggers on MyISAM (and I really don&#039;t know yet what of Maria and Falcon) does not provide you with real integrity. Using LOCK IN SHARE MODE on InnoDB will probably cost a lot.

Nevertheless I still find the DELETE CASCASE simulation to be helpful: it helps in taking out the garbage (orphaned rows).
Otherwise, and with no real FK, cascading deletes must be performed on the application level, or by periodic pruning.</description>
		<content:encoded><![CDATA[<p>Hi Mark,</p>
<p>Thanks. You are right. Using triggers on MyISAM (and I really don&#8217;t know yet what of Maria and Falcon) does not provide you with real integrity. Using LOCK IN SHARE MODE on InnoDB will probably cost a lot.</p>
<p>Nevertheless I still find the DELETE CASCASE simulation to be helpful: it helps in taking out the garbage (orphaned rows).<br />
Otherwise, and with no real FK, cascading deletes must be performed on the application level, or by periodic pruning.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Callaghan</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-227</link>
		<dc:creator>Mark Callaghan</dc:creator>
		<pubDate>Mon, 05 Jan 2009 17:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-227</guid>
		<description>It is not easy to implement referential integrity with triggers on storage engines that allow concurrent transactions.  The trigger that confirms that the referenced Country exists on inserts to City doesn&#039;t work for InnoDB and might not work for Maria and Falcon. The fix in this case is to change the SELECT to a SELECT ... LOCK IN SHARE MODE.

And given the lack of transactons with MyISAM, is there really a point in trying to enforce referential integrity?</description>
		<content:encoded><![CDATA[<p>It is not easy to implement referential integrity with triggers on storage engines that allow concurrent transactions.  The trigger that confirms that the referenced Country exists on inserts to City doesn&#8217;t work for InnoDB and might not work for Maria and Falcon. The fix in this case is to change the SELECT to a SELECT &#8230; LOCK IN SHARE MODE.</p>
<p>And given the lack of transactons with MyISAM, is there really a point in trying to enforce referential integrity?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/triggers-use-case-compilation-part-i/comment-page-1#comment-224</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Mon, 05 Jan 2009 12:41:39 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=313#comment-224</guid>
		<description>Hi Roland,

Indeed, very useful stuff. I&#039;ll take note to check up on your scripts and utilities. There&#039;s many of them, and it&#039;s hard to keep up!

Shlomi</description>
		<content:encoded><![CDATA[<p>Hi Roland,</p>
<p>Indeed, very useful stuff. I&#8217;ll take note to check up on your scripts and utilities. There&#8217;s many of them, and it&#8217;s hard to keep up!</p>
<p>Shlomi</p>
]]></content:encoded>
	</item>
</channel>
</rss>
