<?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>Transactions on InnoDB &#187; Vasil Dimov</title>
	<atom:link href="http://blogs.innodb.com/wp/author/vasil-dimov/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.innodb.com/wp</link>
	<description>&#34;The word&#34; about InnoDB Products and Technology</description>
	<lastBuildDate>Fri, 23 Dec 2011 11:17:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Shortened warm-up times with a preloaded InnoDB buffer pool</title>
		<link>http://blogs.innodb.com/wp/2011/07/shortened-warm-up-times-with-a-preloaded-innodb-buffer-pool/</link>
		<comments>http://blogs.innodb.com/wp/2011/07/shortened-warm-up-times-with-a-preloaded-innodb-buffer-pool/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 20:53:28 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[Feature]]></category>
		<category><![CDATA[InnoDB Builtin]]></category>
		<category><![CDATA[InnoDB Plugin]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Buffer pool]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=1072</guid>
		<description><![CDATA[Are you running an InnoDB installation with a many-gigabytes buffer pool(s)? Does it take too long before it goes back to speed after a restart? If yes, then the following will be interesting to you. In the latest MySQL 5.6 Labs release we have implemented an InnoDB buffer pool(s) dump and load to solve this [...]]]></description>
			<content:encoded><![CDATA[<p>Are you running an InnoDB installation with a many-gigabytes buffer pool(s)? Does it take too long before it goes back to speed after a restart? If yes, then the following will be interesting to you.</p>
<p>In the latest MySQL 5.6 Labs release we have implemented an InnoDB buffer pool(s) dump and load to solve this problem.</p>
<p>The contents of the InnoDB buffer pool(s) can be saved on disk before MySQL is shut down and then read in after a restart so that the warm up time is drastically shortened &#8211; the buffer pool(s) go to the state they were before the server restart! The time needed for that is roughly the time needed to read data from disk that is about the size of the buffer pool(s).</p>
<p>Lets dive straight into the commands to perform various dump/load operations:</p>
<p>The buffer pool(s) dump can be done at any time when MySQL is running by doing:<span id="more-1072"></span></p>
<pre>  mysql&gt; SET innodb_buffer_pool_dump_now=ON;</pre>
<p>This operation is very quick and creates a file named <em>ib_buffer_pool</em> in the InnoDB data directory, by analogy with the default InnoDB data file <em>ibdata1</em>. The file contains only the space and page IDs and is about 500k per gigabyte of buffer pool. The same operation can also be done automatically during MySQL shutdown:</p>
<pre>  mysql&gt; SET innodb_buffer_pool_dump_at_shutdown=ON;</pre>
<p>By analogy the buffer pool(s) can be loaded manually by:</p>
<pre>  mysql&gt; SET innodb_buffer_pool_load_now=ON;</pre>
<p>and automatically during startup from the file <em>ib_buffer_pool</em> by setting</p>
<pre>  innodb_buffer_pool_load_at_startup=ON</pre>
<p>in my.cnf or my.ini.</p>
<p>The filename where the buffer pool(s) are dumped and later loaded from can be specified by changing the value of the global configuration variable <em>innodb_buffer_pool_filename</em> which defaults to <em>ib_buffer_pool</em>.</p>
<p>Additionally the progress of the buffer pool(s) dump (although very quick) and load (not so quick) can be monitored by:</p>
<pre>  mysql&gt; SHOW STATUS LIKE 'innodb_buffer_pool_dump_status';</pre>
<pre>  mysql&gt; SHOW STATUS LIKE 'innodb_buffer_pool_load_status';</pre>
<p>And finally the load operation can be interrupted by:</p>
<pre>  mysql&gt; SET innodb_buffer_pool_load_abort=ON;</pre>
<p>Before loading the list is sorted so that pages will be read in as close to sequential order as possible. The load is asynchronous so it should not interfere with normal operations too much. The load is clever enough to handle different buffer pool sizes or pages that are missing during the load. A page will not be loaded if it is already in the buffer pool so there is no need to worry about problems with changed pages.</p>
<p>The dump file is plain text so it is possible to edit it, though we do not recommend this.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2011/07/shortened-warm-up-times-with-a-preloaded-innodb-buffer-pool/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>InnoDB Persistent Statistics at last</title>
		<link>http://blogs.innodb.com/wp/2011/04/innodb-persistent-statistics-at-last/</link>
		<comments>http://blogs.innodb.com/wp/2011/04/innodb-persistent-statistics-at-last/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 12:46:23 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[Feature]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=746</guid>
		<description><![CDATA[Background InnoDB gathers statistics for the data in user tables, which are used by the MySQL optimizer to choose the best query plan. For a long time the imprecision and instability of these statistics have been creating problems for users. The problem is that these statistics are recalculated at any of the following events: * [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Background</strong></p>
<p>InnoDB gathers statistics for the data in user tables, which are used by the MySQL optimizer to choose the best query plan. For a long time the imprecision and instability of these statistics have been creating problems for users.</p>
<p>The problem is that these statistics are recalculated at any of the following events:</p>
<p>* When the table is opened</p>
<p>* When the table has changed a lot (1/16th of the table has been updated/deleted or inserted)</p>
<p>* When ANALYZE TABLE is run</p>
<p><span id="more-746"></span></p>
<p>* When SHOW TABLE STATUS or SHOW INDEX FROM is run</p>
<p>* When InnoDB Monitor is turned ON</p>
<p>* others</p>
<p>and so their recalculation must be quick an unnoticeable. Thus the quick algorithm just picks <a href="http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_stats_sample_pages" target="_blank">8 random pages</a> and could give a wildly varying results.</p>
<p><strong>Quick glance</strong></p>
<p>To solve this problem MySQL 5.6.2 introduces the InnoDB Persistent Statistics feature, which:</p>
<p>* Uses a more precise sampling algorithm (which is also slower) in an attempt to better inform the MySQL optimizer so it can choose the best possible query plan.</p>
<p>* Does not recalculate the statistics automatically, only when ANALYZE TABLE is run. This means that the same query plan will always be chosen even when MySQL is restarted (see below). A query plan using the global statistics can only change after ANALYZE TABLE has been run (manually). This also means that the user and/or DBA is responsible for running ANALYZE TABLE regularly if the data in the table has been changed a lot.</p>
<p>* Saves the statistics on disk in normal user-visible and updatable SQL tables.</p>
<p><strong>How to turn it ON?</strong></p>
<p>To turn ON the persistent statistics for a given table you must first create the persistent statistics storage by executing the SQL script storage/innobase/scripts/persistent_storage.sql which is shipped in the source distribution (in future versions it may be executed automatically by mysql_install_db). This script will create a new database named &#8220;innodb&#8221; with two tables in it &#8211; &#8220;table_stats&#8221; and &#8220;index_stats&#8221;. InnoDB will read/write the statistics from/to those tables. Second you must set the new parameter innodb_analyze_is_persistent to ON (it is OFF by default). This will instruct InnoDB to use the better (and slower!) sampling algorithm during ANALYZE TABLE and to save the results to the stats tables. To change the number of leaf pages that are being sampled during such a &#8220;persistent-results&#8221; ANALYZE TABLE set the parameter innodb_stats_persistent_sample_pages to a higher value.</p>
<p>Once the stats &#8220;meta&#8221; tables are present and stats for a given table exist in them, then those stats will be used whenever stats are needed &#8211; including open table/show table status/show index from and others. To stop using them you must DELETE the corresponding rows from innodb.table_stats and innodb.index_stats.</p>
<p><strong>Beware of bugs</strong></p>
<p>Some bugs in persistent stats code which may cause InnoDB to crash have been fixed, but are not included in 5.6.2. See:</p>
<p><a href="http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.262">http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.262</a></p>
<p><a href="http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.266">http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.266</a></p>
<p><a href="http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.271">http://bazaar.launchpad.net/~mysql/mysql-server/mysql-trunk/revision/3167.15.271</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2011/04/innodb-persistent-statistics-at-last/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Only God can make random selections</title>
		<link>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/</link>
		<comments>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 22:51:28 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[InnoDB Builtin]]></category>
		<category><![CDATA[InnoDB Plugin]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=392</guid>
		<description><![CDATA[Recently, it was reported (see MySQL bug #43660) that &#8220;SHOW INDEXES/ANALYZE does NOT update cardinality for indexes of InnoDB table&#8221;. The problem appeared to happen only on 64-bit systems, but not 32-bit systems. The bug turns out to be a case of mistaken identity. The real criminal here wasn&#8217;t the SHOW INDEXES or the ANALYZE [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, it was reported (see MySQL <a href="http://bugs.mysql.com/43660">bug #43660</a>) that &#8220;SHOW INDEXES/ANALYZE does NOT update cardinality for indexes of InnoDB table&#8221;.   The problem appeared to happen only on 64-bit systems, but not 32-bit systems.  The bug turns out to be a case of mistaken identity.  The real criminal here wasn&#8217;t the SHOW INDEXES or the ANALYZE command, but something else entirely.  It wasn&#8217;t specific to 64-bit platforms, either.  Read on for the interesting story about this mystery and its solution &#8230;</p>
<p>InnoDB estimates statistics for the query optimizer by picking random pages from an index.  Upon detailed analysis, we found that the algorithm that picks random pages for estimation always picked the same page, thus producing the same result every time.    This made it appear that the index cardinality was not updated by ANALYZE TABLE. Going deeper, the reason the algorithm always selected the same page was that the random number generator always generated numbers that, when divided by 3, always gave the same remainder (2).</p>
<p>The sampling algorithm selects a random leaf page by starting from the root page and then selecting a random record from it, descending into its child page and so on until it reaches a leaf page. In the particular case that was reported in the bug report, the root page contained only 3 records and the tree height was only 2 (i.e., the leaf pages were all just below the root page).</p>
<p>You can already guess what happened.  The &#8220;random&#8221; numbers generated, not being so random, caused the algorithm to always pick the same record from the root page (the second one) and then descend to the leaf page below it. Every time.  So, the 8 random pages that were sampled in order to get an estimate of the whole picture were in fact the same page, even in isolated ANALYZE TABLE runs.  </p>
<p>So, clearly there was a problem with the random number generator.  But why didn&#8217;t this problem seem to appear on 64-bit platforms?   It would have, had we only enough time to wait.  The random number generator, always generating numbers like 3k+2 of type unsigned long, at some point wrapped around 4 billion on 32-bit machines and started generating numbers like 3k+1. On 64-bit machines, where unsigned long is much bigger, this wrap did not occur.   But it would have occurred if we ran the test for 1000 years!. </p>
<p><span id="more-392"></span></p>
<p>So, on 32-bit machines, at some point the first record from the root page was picked instead of the second one, and this caused some changes in the results produced by ANALYZE TABLE. Yet, on 64-bit machines, for all practical purposes, this &#8220;never&#8221; happens.  By only looking at the symptoms, one would get the impression that the flaw existed only on 64-bit machines and that 32-bit systems were ok.</p>
<p>Well, what about the fix?  A possible fix would be to change InnoDB in 64-bit environments to behave the same way it does in 32-bit environments. People who are used to the behavior of InnoDB on 32-bit machines and upgrade to a 64-bit machine might be satisfied, because the problem on 64-bit systems was &#8220;solved&#8221;.  But in reality, this approach in no way would fix the underlying problem.  The real solution is to replace the random number generator with a better one (fully realizing that algorithmic random number generators are only <em>pseudo</em>-random number generators).</p>
<p>Yet even that is not so simple.  Making any change would have caused changes to index cardinality estimations, thereby causing changes in decisions made by the optimizer, resulting in different execution plans &#8230; and different, possibly worse, performance for queries. Because MySQL 5.1 and 5.0 are frozen for such drastic changes, we fixed this bug in the upcoming 1.0.4 release of the <a href="http://www.innodb.com/innodb_plugin/">InnoDB Plugin</a>.</p>
<p>In order to not break existing applications, and since many people wanted a fix for MySQL 5.0 and 5.1, we implemented this fix for MySQL under the control of a new configuration parameter (innodb_use_legacy_cardinality_algorithm), which is turned on by default, preserving past behavior.  Because the &#8220;right fix&#8221; is to permanently change the random number generator, this new configuration parameter is not present in the InnoDB Plugin, and the &#8220;more random&#8221; random number generator will always be used.</p>
<p>And that is the end of the case of mistaken identity.   It turns out that it is really hard to generate truly random numbers, hence the title of this blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Software is Hard Sometimes &#8230;</title>
		<link>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/</link>
		<comments>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:00:59 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[InnoDB Plugin]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[mutex]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[portability]]></category>
		<category><![CDATA[Scalability]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=350</guid>
		<description><![CDATA[Some months ago, Google released a patch for InnoDB that boosts performance on multi-core servers. We decided to incorporate the change into the InnoDB Plugin to make everybody happy: users of InnoDB don&#8217;t have to apply the patch, and Google no longer has to maintain the patch for new versions of InnoDB. And it makes [...]]]></description>
			<content:encoded><![CDATA[<p>Some months ago, Google released a <a href="http://code.google.com/p/google-mysql-tools/wiki/SmpPerformance">patch</a> for InnoDB that boosts performance on multi-core servers.  We decided to incorporate the change into the InnoDB Plugin to make everybody happy: users of InnoDB don&#8217;t have to apply the patch, and Google no longer has to maintain the patch for new versions of InnoDB.  And it makes us at Innobase happy because it improves our product (as you can in <a href="http://blogs.innodb.com/wp/2009/03/plug-in-for-performance-and-scalability/">this post</a> about InnoDB Plugin release 1.0.3).</p>
<p>However, there are always technical and business issues to address.  Given the low-level changes in the patch, was it technically sound?   Was the patch stable and as rock solid as is the rest of InnoDB?  Although it was written for the built-in InnoDB in MySQL 5.0.37, we needed to adapt it to the InnoDB Plugin. Could we make the patch portable to many platforms?   Could we incorporate the patch without legal risk (so it could be licensed under both the GPL and commercial terms)?</p>
<p>Fortunately Google generously donated the patch to us under the BSD license, so there was no concern about intellectual property (so long as we properly acknowledged the contribution, which we do in an Appendix to the manual and in the source code).  So, while the folks at Google are known for writing excellent code, we had to thoroughly review and test the patch before it could be incorporated in a release of InnoDB.</p>
<p>The patch improves performance by replacing InnoDB mutex and rw-mutex with atomic memory instructions. The first issue that arose was that the patch assigned the integer value -1 to a pthread_t variable, to refer to a neutral/non-existent thread identifier.  This approach worked for Google because they use InnoDB solely on Linux. As it happens, pthread_t is defined as an integer on Linux.</p>
<p>But we had problems when the patch was tested on FreeBSD.  We still needed to reference a non-existent thread, but in some environments (e.g. some versions of HPUX, Mac OS X) pthread_t is defined as a<br />
structure, not an integer.  As we looked at it, the problem became more complex.  For this scheme to work, it must be possible to change thread identifiers atomically, using a Compare-And-Swap instruction.  Otherwise, there will be subtle, mysterious and nasty failures.</p>
<p><span id="more-350"></span></p>
<p>We thought about enabling this patch only on Linux.  But that approach was not optimal, because the patch could work perfectly well on other platforms where pthread_t is the same size as the machine word, like FreeBSD and Solaris, for example.   We could have simply enumerated the operating system names where the patch would be supported, but this too was far from perfect.  The ability to use the atomic instructions depends not only on the operating system, but the GCC version (has to be 4.1 or newer) and the capabilities of the CPU (some CPUs do not support Compare-And-Swap!).</p>
<p>So, we developed a dynamic compile-time check for checking whether the target environment (pthread_t type and size, GCC version, CPU capabilities) supports the use of atomic instructions as intended. This seemed to be the best approach, but then another problem arose! </p>
<p>Dynamic compile-time checks (i.e. autoconf) are part of the MySQL&#8217;s ./configure script.  Innobase does not control this script, and so we must live with what is distributed by MySQL.  To make things simple for<br />
users, we wanted to avoid asking the users to re-create ./configure with the autotools. So we simply injected the required checks in the Makefile.  This seemed to work fine.   Only after release of the InnoDB Plugin 1.0.3 did a small crack in this approach arise.  Fortunately this problem turned out to be easy to fix and only occurs if one compiles with &#8220;make -j&#8221; (in order to perform the make in parallel). See <a href="http://bugs.mysql.com/43740">Bug#43740</a> for details and for a fix.</p>
<p>The bottom line is that sometimes more goes on &#8220;behind the scenes&#8221; than you might expect when it comes to incorporating a third-party contribution into a product.  We are grateful for the Google patch, and are glad that we have been able to include it in the InnoDB Plugin in a way that maximizes its portability, while keeping things as simple as possible for users.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

