<?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>Percona&#039;s MySQL &#38; InnoDB performance and scalability blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 16:45:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: vitamin-R</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-866620</link>
		<dc:creator>vitamin-R</dc:creator>
		<pubDate>Fri, 30 Dec 2011 18:16:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-866620</guid>
		<description>Juan, just make your log table InnoDb too, to get rid of the table locks.

Use something like &quot;ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8&quot; if you need it to use less disk space.</description>
		<content:encoded><![CDATA[<p>Juan, just make your log table InnoDb too, to get rid of the table locks.</p>
<p>Use something like &#8220;ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8&#8243; if you need it to use less disk space.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-834577</link>
		<dc:creator>Juan</dc:creator>
		<pubDate>Wed, 26 Oct 2011 08:46:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-834577</guid>
		<description>I&#039;m using a trigger on an innodb table that &quot;dumps&quot; any updates to the table to a myisam table holding a log of updates.
The update table has the same primary key than the primary table.
The idea is to keep the last change for every primary key (well, I don&#039;t dump the whole rows, but only some selected fields that I need in the log).
The trigger uses INSERT ON DUPLICATE KEY UPDATE to achieve that.
The problem is that I find many locked queries in the db as soon as there&#039;s a bit of update activity over the primary table. It even looks like there might be some deadlock (or I don&#039;t find an explanation for such long locks in so many queries), but I can&#039;t find any reason in the code for that.
I was wondering if INSERT ... UPDATE might lock for read access (or lock only the index, or something simmilar) while checking for key value existence, as inserts in myisam are concurrent with reads, and then try to lock for write access when performing the update. This would lead to a deadlock when trying to upgrade two read locks to write locks or any equivalent situation.
My version is 5.1.49-3-log.
Is it possible that a problem like the one I described is really happenning?
Might a REPLACE solve the issue? Would it work right where INSERT ... UPDATE locks?</description>
		<content:encoded><![CDATA[<p>I&#8217;m using a trigger on an innodb table that &#8220;dumps&#8221; any updates to the table to a myisam table holding a log of updates.<br />
The update table has the same primary key than the primary table.<br />
The idea is to keep the last change for every primary key (well, I don&#8217;t dump the whole rows, but only some selected fields that I need in the log).<br />
The trigger uses INSERT ON DUPLICATE KEY UPDATE to achieve that.<br />
The problem is that I find many locked queries in the db as soon as there&#8217;s a bit of update activity over the primary table. It even looks like there might be some deadlock (or I don&#8217;t find an explanation for such long locks in so many queries), but I can&#8217;t find any reason in the code for that.<br />
I was wondering if INSERT &#8230; UPDATE might lock for read access (or lock only the index, or something simmilar) while checking for key value existence, as inserts in myisam are concurrent with reads, and then try to lock for write access when performing the update. This would lead to a deadlock when trying to upgrade two read locks to write locks or any equivalent situation.<br />
My version is 5.1.49-3-log.<br />
Is it possible that a problem like the one I described is really happenning?<br />
Might a REPLACE solve the issue? Would it work right where INSERT &#8230; UPDATE locks?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: s.mateev</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-767650</link>
		<dc:creator>s.mateev</dc:creator>
		<pubDate>Wed, 23 Jun 2010 12:46:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-767650</guid>
		<description>Consider the following:

DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
`person_id` int(11) NOT NULL auto_increment,
`name` varchar(60) character set utf8 NOT NULL,
`social_security_number` bigint(20) NOT NULL,
PRIMARY KEY (`person_id`),
UNIQUE KEY `social_security_number` (`social_security_number`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

TRUNCATE TABLE person;
INSERT INTO person (name, social_security_number) VALUES (â€˜Aliceâ€™, 123456);
INSERT INTO person (name, social_security_number) VALUES (â€˜Bobâ€™, 787878);
REPLACE INTO person (name, social_security_number) VALUES (â€˜Bobâ€™, 787878);

Both on InnoDB and on MyISAM, the results are:

+-----------+-------+------------------------+
&#124; person_id &#124; name &#124; social_security_number &#124;
+-----------+-------+------------------------+
&#124; 1 &#124; Alice &#124; 123456 &#124;
&#124; 3 &#124; Bob &#124; 787878 &#124;
+-----------+-------+------------------------+

If the primary key value changes, I think the slot can&#039;t be reused.

With regard to having more than one row removed â€“ nice! I agree that it must be used appropriately.</description>
		<content:encoded><![CDATA[<p>Consider the following:</p>
<p>DROP TABLE IF EXISTS `person`;<br />
CREATE TABLE `person` (<br />
`person_id` int(11) NOT NULL auto_increment,<br />
`name` varchar(60) character set utf8 NOT NULL,<br />
`social_security_number` bigint(20) NOT NULL,<br />
PRIMARY KEY (`person_id`),<br />
UNIQUE KEY `social_security_number` (`social_security_number`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1;</p>
<p>TRUNCATE TABLE person;<br />
INSERT INTO person (name, social_security_number) VALUES (â€˜Aliceâ€™, 123456);<br />
INSERT INTO person (name, social_security_number) VALUES (â€˜Bobâ€™, 787878);<br />
REPLACE INTO person (name, social_security_number) VALUES (â€˜Bobâ€™, 787878);</p>
<p>Both on InnoDB and on MyISAM, the results are:</p>
<p>+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| person_id | name | social_security_number |<br />
+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| 1 | Alice | 123456 |<br />
| 3 | Bob | 787878 |<br />
+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>If the primary key value changes, I think the slot can&#8217;t be reused.</p>
<p>With regard to having more than one row removed â€“ nice! I agree that it must be used appropriately.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ayman</title>
		<link>http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/comment-page-1/#comment-767642</link>
		<dc:creator>Ayman</dc:creator>
		<pubDate>Wed, 23 Jun 2010 10:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-update-and-replace-into/#comment-767642</guid>
		<description>Thanks for all who share their knowledge here. 
I guess I need to use the REPLACE statement, but there is a question in my head: 
If the auto-increment primary key is 7 now (for example), after doing REPLACE for the 7th row or less than 7, what will be the next auto-increment value? will it be 8 or 9?</description>
		<content:encoded><![CDATA[<p>Thanks for all who share their knowledge here.<br />
I guess I need to use the REPLACE statement, but there is a question in my head:<br />
If the auto-increment primary key is 7 now (for example), after doing REPLACE for the 7th row or less than 7, what will be the next auto-increment value? will it be 8 or 9?</p>
]]></content:encoded>
	</item>
	<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&#038;#8230" rel="nofollow">http://www.mysqlperformanceblog.com/2007/01/18/insert-on-duplicate-key-u&#038;#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>
</channel>
</rss>

