<?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: INSERT ON DUPLICATE KEY UPDATE and REPLACE INTO</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jeff</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-647055</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Fri, 04 Sep 2009 20:42:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-647055</guid>
		<description>One benefit of REPLACE over UPDATE is the DELAYED feature, which comes in handy.</description>
		<content:encoded><![CDATA[<p>One benefit of REPLACE over UPDATE is the DELAYED feature, which comes in handy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Possible improvement with caches &#124; reexport</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-327413</link>
		<dc:creator>Possible improvement with caches &#124; reexport</dc:creator>
		<pubDate>Sun, 13 Jul 2008 15:55:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-327413</guid>
		<description>[...] http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-u&#8230; High performance [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-u&#8230" rel="nofollow">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-u&#8230</a>; High performance [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: G Barnes</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-274789</link>
		<dc:creator>G Barnes</dc:creator>
		<pubDate>Sun, 13 Apr 2008 15:46:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-274789</guid>
		<description>I have two identical tables named Table1 and Table2 on two computers respectivaly. There are two fields in each, &quot;ITEM&quot; and &quot;SOLD&quot;. In both tables, &quot;ITEM&quot; is the primary key. Is there a way to merge Table1 into Table2 with something similar to INSERT ON DUPLICATE UPDATE sold =sold +(the first table&#039;s sold value)? Thus if Table1 contains 10 (in the  sold field) and Table2 contains 20. I want the total in Table 2 to be 30. Is this possible?</description>
		<content:encoded><![CDATA[<p>I have two identical tables named Table1 and Table2 on two computers respectivaly. There are two fields in each, &#8220;ITEM&#8221; and &#8220;SOLD&#8221;. In both tables, &#8220;ITEM&#8221; is the primary key. Is there a way to merge Table1 into Table2 with something similar to INSERT ON DUPLICATE UPDATE sold =sold +(the first table&#8217;s sold value)? Thus if Table1 contains 10 (in the  sold field) and Table2 contains 20. I want the total in Table 2 to be 30. Is this possible?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P.ANBALAGAN</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-251134</link>
		<dc:creator>P.ANBALAGAN</dc:creator>
		<pubDate>Mon, 10 Mar 2008 07:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-251134</guid>
		<description>I WANT QUERY FOR TO INSERT MORE 100000 RECORDS IN A TABLE.</description>
		<content:encoded><![CDATA[<p>I WANT QUERY FOR TO INSERT MORE 100000 RECORDS IN A TABLE.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Haddad</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-46609</link>
		<dc:creator>Jonathan Haddad</dc:creator>
		<pubDate>Wed, 07 Feb 2007 19:03:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-46609</guid>
		<description>Jerry:
Thanks for the tip - I&#039;ll be sure to keep that in mind.  For the most part, in what I do, INSERT ON DUPLICATE UPDATE is what I need to use, especially knowing the cascading keys issue.</description>
		<content:encoded><![CDATA[<p>Jerry:<br />
Thanks for the tip &#8211; I&#8217;ll be sure to keep that in mind.  For the most part, in what I do, INSERT ON DUPLICATE UPDATE is what I need to use, especially knowing the cascading keys issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Ventimiglia</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-40486</link>
		<dc:creator>John Ventimiglia</dc:creator>
		<pubDate>Wed, 31 Jan 2007 15:02:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-40486</guid>
		<description>Also related to Jerrys comments, REPLACE will use the next available # on auto-increment fields, which may not always be desired.</description>
		<content:encoded><![CDATA[<p>Also related to Jerrys comments, REPLACE will use the next available # on auto-increment fields, which may not always be desired.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-35018</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Tue, 23 Jan 2007 01:24:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-35018</guid>
		<description>Thanks Jerry, 

Good catch.</description>
		<content:encoded><![CDATA[<p>Thanks Jerry, </p>
<p>Good catch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Zheng</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-35017</link>
		<dc:creator>Jerry Zheng</dc:creator>
		<pubDate>Tue, 23 Jan 2007 01:16:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-35017</guid>
		<description>Here is a test case:

mysql&gt; select version();
+---------------------+
&#124; version()           &#124;
+---------------------+
&#124; 4.1.18-standard-log &#124;
+---------------------+


mysql&gt; create table p(id int primary key, notid int) type=innodb;
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql&gt; create table c (id int primary key, fk int , foreign key (fk) references p(id) on delete CASCADE ) type=innodb;
Query OK, 0 rows affected, 1 warning (0.06 sec)

mysql&gt; insert into p values (1,1), (2,2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql&gt; insert into c values (1,1), (2,2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql&gt; select * from p;
+----+-------+
&#124; id &#124; notid &#124;
+----+-------+
&#124;  1 &#124;     1 &#124;
&#124;  2 &#124;     2 &#124;
+----+-------+
2 rows in set (0.00 sec)

mysql&gt; select * from c;
+----+------+
&#124; id &#124; fk   &#124;
+----+------+
&#124;  1 &#124;    1 &#124;
&#124;  2 &#124;    2 &#124;
+----+------+
2 rows in set (0.00 sec)

mysql&gt; replace into p values (1,10);
Query OK, 2 rows affected (0.00 sec)

mysql&gt; select * from c;
+----+------+
&#124; id &#124; fk   &#124;
+----+------+
&#124;  2 &#124;    2 &#124;
+----+------+
1 row in set (0.00 sec)

-- We lost the child #1.

mysql&gt; insert into p (id, notid) values (2,20) on duplicate key update notid=20;
Query OK, 2 rows affected (0.01 sec)

mysql&gt; select * from c;
+----+------+
&#124; id &#124; fk   &#124;
+----+------+
&#124;  2 &#124;    2 &#124;
+----+------+
1 row in set (0.00 sec)

-- Child #2 is safe.

mysql&gt; select * from p;
+----+-------+
&#124; id &#124; notid &#124;
+----+-------+
&#124;  1 &#124;    10 &#124;
&#124;  2 &#124;    20 &#124;
+----+-------+
2 rows in set (0.00 sec)</description>
		<content:encoded><![CDATA[<p>Here is a test case:</p>
<p>mysql&gt; select version();<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| version()           |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| 4.1.18-standard-log |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>mysql&gt; create table p(id int primary key, notid int) type=innodb;<br />
Query OK, 0 rows affected, 1 warning (0.07 sec)</p>
<p>mysql&gt; create table c (id int primary key, fk int , foreign key (fk) references p(id) on delete CASCADE ) type=innodb;<br />
Query OK, 0 rows affected, 1 warning (0.06 sec)</p>
<p>mysql&gt; insert into p values (1,1), (2,2);<br />
Query OK, 2 rows affected (0.00 sec)<br />
Records: 2  Duplicates: 0  Warnings: 0</p>
<p>mysql&gt; insert into c values (1,1), (2,2);<br />
Query OK, 2 rows affected (0.00 sec)<br />
Records: 2  Duplicates: 0  Warnings: 0</p>
<p>mysql&gt; select * from p;<br />
+&#8212;-+&#8212;&#8212;-+<br />
| id | notid |<br />
+&#8212;-+&#8212;&#8212;-+<br />
|  1 |     1 |<br />
|  2 |     2 |<br />
+&#8212;-+&#8212;&#8212;-+<br />
2 rows in set (0.00 sec)</p>
<p>mysql&gt; select * from c;<br />
+&#8212;-+&#8212;&#8212;+<br />
| id | fk   |<br />
+&#8212;-+&#8212;&#8212;+<br />
|  1 |    1 |<br />
|  2 |    2 |<br />
+&#8212;-+&#8212;&#8212;+<br />
2 rows in set (0.00 sec)</p>
<p>mysql&gt; replace into p values (1,10);<br />
Query OK, 2 rows affected (0.00 sec)</p>
<p>mysql&gt; select * from c;<br />
+&#8212;-+&#8212;&#8212;+<br />
| id | fk   |<br />
+&#8212;-+&#8212;&#8212;+<br />
|  2 |    2 |<br />
+&#8212;-+&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>&#8211; We lost the child #1.</p>
<p>mysql&gt; insert into p (id, notid) values (2,20) on duplicate key update notid=20;<br />
Query OK, 2 rows affected (0.01 sec)</p>
<p>mysql&gt; select * from c;<br />
+&#8212;-+&#8212;&#8212;+<br />
| id | fk   |<br />
+&#8212;-+&#8212;&#8212;+<br />
|  2 |    2 |<br />
+&#8212;-+&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>&#8211; Child #2 is safe.</p>
<p>mysql&gt; select * from p;<br />
+&#8212;-+&#8212;&#8212;-+<br />
| id | notid |<br />
+&#8212;-+&#8212;&#8212;-+<br />
|  1 |    10 |<br />
|  2 |    20 |<br />
+&#8212;-+&#8212;&#8212;-+<br />
2 rows in set (0.00 sec)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Zheng</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-35016</link>
		<dc:creator>Jerry Zheng</dc:creator>
		<pubDate>Tue, 23 Jan 2007 01:07:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-35016</guid>
		<description>The two statements have different impact for INNODb table. 
The REPLACE INTO acts as DELETE/INSERT for duplicates. 
The INSERT ON DUPLIACTE UPDATE is true update. 

If you have a child table defined with &quot;on delete CASCADE&quot;, the REPLACE INTO will delete the child record too.

I will use INSERT ON DUPLICATE rather than the REPLACE INTO for the above reason.</description>
		<content:encoded><![CDATA[<p>The two statements have different impact for INNODb table.<br />
The REPLACE INTO acts as DELETE/INSERT for duplicates.<br />
The INSERT ON DUPLIACTE UPDATE is true update. </p>
<p>If you have a child table defined with &#8220;on delete CASCADE&#8221;, the REPLACE INTO will delete the child record too.</p>
<p>I will use INSERT ON DUPLICATE rather than the REPLACE INTO for the above reason.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-32194</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 18 Jan 2007 20:11:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-32194</guid>
		<description>Sure, 

I do not have benchmarks with Innodb but I&#039;d expect them to be close.  I&#039;d mostly look at what makes more sense for your application from development standpoint.</description>
		<content:encoded><![CDATA[<p>Sure, </p>
<p>I do not have benchmarks with Innodb but I&#8217;d expect them to be close.  I&#8217;d mostly look at what makes more sense for your application from development standpoint.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
