<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Krzykawski.com &#187; MySQL</title>
	<atom:link href="http://krzykawski.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://krzykawski.com</link>
	<description>Opensource, work, projects - sharing the fun.</description>
	<lastBuildDate>Thu, 29 Dec 2011 09:46:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Interesting new thread..</title>
		<link>http://krzykawski.com/2011/04/16/interesting-new-thread/</link>
		<comments>http://krzykawski.com/2011/04/16/interesting-new-thread/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 21:12:03 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[Confereces]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=163</guid>
		<description><![CDATA[Concluded the MySQL UC (called the O&#8217;Reilly MySQL Conference &#38; Expo nowadays).. There was a lot of interesting stuff going on, and was great to get a refresher.. It was also a useful &#8220;see how others do it&#8221; exercise. Something that come to mind is the new threads added in InnoDB. To bad they show up [...]]]></description>
			<content:encoded><![CDATA[<p>Concluded the MySQL UC (called the O&#8217;Reilly MySQL Conference &amp; Expo nowadays).. There was a lot of interesting stuff going on, and was great to get a refresher.. It was also a useful &#8220;see how others do it&#8221; exercise.</p>
<p>Something that come to mind is the new threads added in InnoDB. To bad they show up first in 5.6.2+. We would have needed them now.. <img src='http://krzykawski.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But isn&#8217;t that always the case? We are facing the trouble of grooming a table from loads of historical data. It&#8217;s running InnoDB, so we all know it&#8217;s kinda expensive to do massive deletes from it. Especially if you&#8217;re not doing it on your PK. We were debating how to setup a groomer job on a table like this, and no matter how we do it, the only feasible way is to delete by PK. Massive data deletes will still cause for performance degradation when the pages become to dirty. This has of course changed in the new additions to InnoDB in 5.6.2+. Deleting by PK is still the fastest way, and will be faster when we one day switch to 5.6.x. Read more about the new InnoDB stuff here: <a href="http://blogs.innodb.com/wp/2011/04/introducing-page_cleaner-thread-in-innodb/" target="_blank">InnoDB Page Cleaner Thread</a></p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2011/04/16/interesting-new-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL UC 2011 Concluded.</title>
		<link>http://krzykawski.com/2011/04/16/mysql-uc-2011-concluded/</link>
		<comments>http://krzykawski.com/2011/04/16/mysql-uc-2011-concluded/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 23:37:58 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[Confereces]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=165</guid>
		<description><![CDATA[MySQL UC 2011 (Now called O&#8217;Reilly MySQL Conference &#38; Expo) concluded yesterday. It was for sure a very rewarding conference, but one may debate the absence of MySQL itself (Oracle). Normally there is a lot going on, and a lot of announcements from MySQL. In this case Oracle owns MySQL. I don&#8217;t know if they [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL UC 2011 (Now called O&#8217;Reilly MySQL Conference &amp; Expo) concluded yesterday.</p>
<p>It was for sure a very rewarding conference, but one may debate the absence of MySQL itself (Oracle). Normally there is a lot going on, and a lot of announcements from MySQL. In this case Oracle owns MySQL. I don&#8217;t know if they are trying to make a statement, not showing up and providing information to the community. Or are they to self absorbed, and want to pull Open database people to join on Oracle World? I don&#8217;t know, and I really hope it&#8217;s not the latter. They seem to put a lot of money and effort into continued development of MySQL and InnoDB.</p>
<p>Monty did a bald move in his keynote, and later had to appologize in a public blog post: <a href="http://monty-says.blogspot.com/" target="_blank">monty says</a>. Me and Tobias Asplund had a decent chat with him at the SkySQL dinner, and there is a lot of new interesting stuff happening in MariaDB. A lot of effort has been put into subquery optimization and the execution plans are now better than ever. Hopefully Oracle will not be too scared to adopt those patches. We will have to try MariaDB here at Marin to see if we&#8217;ll get any performance improvements running subqueries. It&#8217;s not a production test just to calm those worried souls. <img src='http://krzykawski.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I enjoyed Yoshinori Matsunobo&#8217;s Tutorial. There was a lot of refreshing material, but also some new things I have not been able to test before. Good stuff! Check out <a href="http://yoshinorimatsunobu.blogspot.com/" target="_blank">Matsunobos blog</a></p>
<p>I also enjoyed many of the facebook talks. It&#8217;s very giving to see how they attack some of the problems others never see. The amount of servers and data those guys are handling is insane. Their data drift spotting stuff was awesome as well.</p>
<p>I am surprised by the amount of people looking for DBA&#8217;s or data architects. Almost all talks or keynotes said they were hiring.</p>
<p>All in all, it was a great conference. I am almost looking forward to the next one. <img src='http://krzykawski.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2011/04/16/mysql-uc-2011-concluded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATE on huge table without index</title>
		<link>http://krzykawski.com/2010/09/15/update-on-huge-table-without-index/</link>
		<comments>http://krzykawski.com/2010/09/15/update-on-huge-table-without-index/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 13:10:45 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=143</guid>
		<description><![CDATA[This is something that keeps coming back no matter where I work. It&#8217;s always something I do the same, but it takes a minute to remember how I did it last time. I guess it&#8217;s time to share something super easy. Scenario: You have a huge table with constant activity, containing terabytes of data. You [...]]]></description>
			<content:encoded><![CDATA[<p>This is something that keeps coming back no matter where I work. It&#8217;s always something I do the same, but it takes a minute to remember how I did it last time. I guess it&#8217;s time to share something super easy.</p>
<p><strong>Scenario:</strong><br />
You have a huge table with constant activity, containing terabytes of data. You need to update/delete roughly a million random rows. Random selects from the table keep some indexes you could use hot. Running a big update, locking rows/table is not an option since you have approx. 40-50 inserts/sec to the table. So you need to run smaller batches when updating table. LIMIT would be nice, but is not supported with OFFSET when using UPDATE or DELETE.</p>
<p>Updating using IN and subquery together with limit is not supported in 5.0.x (usure about 5.1.x and forward), Else this would have been a viable solution.</p>
<p>Selects with specific where clauses might take longer due to some indexes/keys being too big as well</p>
<p><strong>Solution:</strong><br />
Selecting all Unique/Primary keys to a temp table with an auto increment primary key and then update the production table using this temporary table as a reference table to which rows to update, with a BETWEEN clause on the temporary table&#8217;s auto_increment field.<br />
May also enclose everything in a transaction and delete the same &#8216;between&#8217; on the temporary reference table. Will help you keep track of what you actually did in case you need to abort this.</p>
<p><strong>Example</strong><br />
Production table:</p>
<blockquote><p>CREATE TABLE `huge_table` (<br />
`request_id` bigint(20) NOT NULL auto_increment,<br />
`customer_id` int(11) default NULL,<br />
`data_id` bigint(20) default NULL,<br />
`group_id` int(11) default NULL,<br />
`user_id` int(11) default NULL,<br />
`action_id` int(11) default NULL,<br />
`external_id` int(11) default NULL,<br />
`user_data` varchar(2048) default NULL,<br />
`entry` text,<br />
`extra_term` varchar(255) default NULL,<br />
`transaction` text,<br />
`receive_time` datetime default NULL,<br />
`from_id` varchar(32) default NULL,<br />
`url` varchar(2048) default NULL,<br />
`from_ip` varchar(2048) default NULL,<br />
`useragent` varchar(2048) default NULL,<br />
`tz` int(11) default NULL,<br />
`cvalue` varchar(255) default NULL,<br />
`rvalue` varchar(255) default NULL,<br />
`uid` varchar(40) default NULL,<br />
PRIMARY KEY  (`request_id`),<br />
KEY `k1` (`receive_time`,`action_id`,`url`,`from_id`)<br />
) ENGINE=InnoDB AUTO_INCREMENT=1047142423 DEFAULT CHARSET=utf8</p></blockquote>
<p>You need to update action_id = 100 on approx 1.5m rows which have receive_time between &#8217;2010-08-01 00:00:00&#8242; and &#8217;2010-08-31 23:59:59&#8242; where from_id equals &#8216;q7b4x5aa0303erer&#8217;.</p>
<p>temporary table:</p>
<blockquote><p>CREATE TABLE `tmp_ids` (<br />
`id` int(11) NOT NULL auto_increment,<br />
`prod_id` bigint(20) default NULL,<br />
PRIMARY KEY  (`id`)<br />
) ENGINE=MyISAM AUTO_INCREMENT=15424160 DEFAULT CHARSET=utf8</p></blockquote>
<p>Fill the temporary table with the id&#8217;s you need to update in the production table:</p>
<blockquote><p>INSERT INTO tmp_ids SELECT * FROM huge_table USE INDEX (k1) WHERE from_id=&#8217;q7b4x5aa0303erer&#8217; AND receive_time BETWEEN &#8217;2010-08-01 00:00:00&#8242; AND &#8217;2010-08-31 23:59:59&#8242;;</p></blockquote>
<p>Then just iterate this in a bash script or our favorite scripting language (increasing the between values of course):</p>
<blockquote><p>UPDATE huge_table ht JOIN tmp_ids ti ON ht.request_id=ti.prod_id SET ht.action_id=100 WHERE ti.id BETWEEN x AND x;</p></blockquote>
<p>example bash script:</p>
<blockquote><p>#!/bin/bash</p>
<p># Config params<br />
user=&#8221;username&#8221;<br />
pass=&#8221;password&#8221;<br />
host=&#8221;hostname&#8221;<br />
db=&#8221;schema_name&#8221;<br />
tmptbl=&#8221;tmp_table&#8221;<br />
livetbl=&#8221;live_table&#8221;<br />
tmpcol=&#8221;live_id&#8221;<br />
livecol=&#8221;request_id&#8221;<br />
tmpkey=&#8221;id&#8221;<br />
upcol=&#8221;from_id=1&#8243;<br />
waittime=&#8221;0.5&#8243;</p>
<p># Print usage function<br />
function usage() {<br />
	echo &#8220;$(basename $0) <rows>&#8221;<br />
	echo &#8220;rows &#8211; number of rows in one go.&#8221;<br />
	exit 0<br />
}</p>
<p># Since we need atleast one variable to continue, check so first variable is supplied<br />
[ -e $1 ] &#038;&#038; usage &#038;&#038; exit</p>
<p># get that variable<br />
rows=$1<br />
# Check which is the first key we will use in temp table<br />
s=`mysql -N -u$user -p$pass -h$host $db -e&#8221;select min(id) from $db.$tmptbl;&#8221;`<br />
# Set latter between value<br />
let b=$s+$rows;<br />
# Count how many rows we have to update so we know how long to loop<br />
count=`mysql -N -u$user -p$pass -h$host $db -e&#8221;select count(*) from $db.$tmptbl;&#8221;|head`;</p>
<p># Print starting line<br />
echo &#8220;Starting up with updates from id: $s to $b, performing $rows at one go..&#8221;</p>
<p># loop till we are done<br />
while [ 1 ];<br />
do</p>
<p># are we done? If so exit<br />
	if (($count <= 0));<br />
		then<br />
		exit<br />
	fi</p>
<p># Run actual db updates<br />
	echo -n "updating $livetbl between $s and $b.."<br />
	mysql -N -u$user -p$pass -h$host $db -e"update $livetbl td join $tmptbl i on td.$livecol=i.$tmpcol set $setval where i.$tmpkey between $s and $b"<br />
	echo -n " deleting in $tmptbl.."<br />
	mysql -N -u$user -p$pass -h$host $db -e"delete from $db.$tmptbl where $tmpkey between $s and $b"<br />
	echo -n " Done!"</p>
<p># set between rows<br />
	let s=$s+$rows<br />
	let b=$b+$rows<br />
	let count=$count-$rows</p>
<p># wait if there are more records to update<br />
	if (($count > 0));<br />
	then<br />
		echo &#8221; ..waiting.. still $count records to update&#8221;;<br />
		sleep $waittime<br />
	fi<br />
done</p>
<p># All done<br />
echo &#8220;Script done. No more records to update&#8221;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2010/09/15/update-on-huge-table-without-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL User Conference 2009</title>
		<link>http://krzykawski.com/2009/03/07/mysql-user-conference-2009/</link>
		<comments>http://krzykawski.com/2009/03/07/mysql-user-conference-2009/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 09:16:27 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[Confereces]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=72</guid>
		<description><![CDATA[Thought i will update you guys a bit about MySQL UC this year. As you may already know i will be holding a session together with Anders Karlsson from MySQL/SUN about MySQL HA. We will walk through different solutions and mention pros and cons of them. I will also present how we solved the HA [...]]]></description>
			<content:encoded><![CDATA[<p>Thought i will update you guys a bit about MySQL UC this year.</p>
<p>As you may already know i will be holding a session together with Anders Karlsson from MySQL/SUN about MySQL HA. We will walk through different solutions and mention pros and cons of them. I will also present how we solved the HA situation at bwin games ab.</p>
<p>Those of you who still have not booked their tickets and entry to MySQL UC, i have a surprise for you! Book your entry now and use this promotion code &#8220;<strong>mys09fsp</strong>&#8221; and you will get <strong>20% off</strong> your total cost! Isn&#8217;t that awesome? Just enter the code at the signup/booking page and you will receive the discount.</p>
<p>Looking forward to see you guys at MySQL UC in Santa Clara. Write me a email if you are going and we&#8217;ll try to hook up. Probably there will be a &#8220;nordic night&#8221; as last year. If you are from around the Nordic/Scandinavian region, make sure to join us. We&#8217;ll probaly be going out and eat something nice and just talk random stuff.</p>
<p>So, what should you do now if you didn&#8217;t already do it? Go to <a title="www.mysqlconf.com" href="http://www.mysqlconf.com" target="_blank">http://www.mysqlconf.com</a> and register for this years MySQL User Conference in Santa Clara / California.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2009/03/07/mysql-user-conference-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaker at MySQL UC 2009</title>
		<link>http://krzykawski.com/2008/12/16/speaker-at-mysql-uc-2009/</link>
		<comments>http://krzykawski.com/2008/12/16/speaker-at-mysql-uc-2009/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:42:56 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=34</guid>
		<description><![CDATA[I together with Anders Karlsson at MySQL/Sun will be speaking about MySQL HA. The title of the talk is MySQL HA, Pros, cons and real world experiences. We will do a walkthrough of technologies that can be used, pros, cons, common pitfalls and how we solved it at bwin games ab (company i work at). [...]]]></description>
			<content:encoded><![CDATA[<p>I together with Anders Karlsson at MySQL/Sun will be speaking about MySQL HA. The title of the talk is <em>MySQL HA, Pros, cons and real world experiences.</em></p>
<p>We will do a walkthrough of technologies that can be used, pros, cons, common pitfalls and how we solved it at <a title="bwin games ab" href="http://www.bwin.com" target="_blank">bwin games ab</a> (company i work at).</p>
<p>I will post more information about this later. Just wanted to share my excitement. <img src='http://krzykawski.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2008/12/16/speaker-at-mysql-uc-2009/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL UC 2008</title>
		<link>http://krzykawski.com/2008/04/28/24/</link>
		<comments>http://krzykawski.com/2008/04/28/24/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 16:36:05 +0000</pubDate>
		<dc:creator>robertk</dc:creator>
				<category><![CDATA[Confereces]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=24</guid>
		<description><![CDATA[I visited MySQL UC 2008 in Santa Clara. It was as usual fun and I met a lot of interesting people. There were 2 other guys from my company attending (Urban and Rickard). My old boss Per did also attend. All in all it was a fun trip. There was a presentation that really stood [...]]]></description>
			<content:encoded><![CDATA[<p>I visited MySQL UC 2008 in Santa Clara. It was as usual fun and I met a lot of interesting people. There were 2 other guys from my company attending (Urban and Rickard). My old boss Per did also attend. All in all it was a fun trip. There was a presentation that really stood out of the whole mass, and it was Dick Hardt with his presentation about identity 2.0. This guys presentation technique is really something different. I have tried to find a recording of it online but have been unsuccessful. If i find it later i will add it to this post.</p>
<p>The whole California visit was not only work. I managed to squeeze in a week of vacation to it. Traveled around NoCal, did some shopping and met some friends.</p>
<p>Edit, i found a recording of Dick Hardts presentation:<a href="http://blip.tv/file/981411">http://blip.tv/file/981411</a></p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2008/04/28/24/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL UC 2007, Santa Clara &#8211; CA</title>
		<link>http://krzykawski.com/2007/04/29/mysql-uc-2007-santa-clara-ca/</link>
		<comments>http://krzykawski.com/2007/04/29/mysql-uc-2007-santa-clara-ca/#comments</comments>
		<pubDate>Sun, 29 Apr 2007 18:31:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Confereces]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://krzykawski.com/?p=17</guid>
		<description><![CDATA[so, i am going to attend the MySQL UC 2007 in Santa Clara, CA &#8211; USA next week. I am actually traveling tomorrow so i can get rid of the worst jet-lag til’ the conference starts the 23:rd of april. Will try to keep something here updated on the way…]]></description>
			<content:encoded><![CDATA[<p>so, i am going to attend the MySQL UC 2007 in Santa Clara, CA &#8211; USA next week. I am actually traveling tomorrow so i can get rid of the worst jet-lag til’ the conference starts the 23:rd of april.</p>
<p>Will try to keep something here updated on the way…</p>
]]></content:encoded>
			<wfw:commentRss>http://krzykawski.com/2007/04/29/mysql-uc-2007-santa-clara-ca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

