<?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>domas mituzas &#187; charsets</title>
	<atom:link href="http://mituzas.lt/tag/charsets/feed/" rel="self" type="application/rss+xml" />
	<link>http://mituzas.lt</link>
	<description></description>
	<lastBuildDate>Thu, 12 Aug 2010 14:09:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Charsets mutex meets InnoDB</title>
		<link>http://mituzas.lt/2009/02/06/charsets-mutex-meets-innodb/</link>
		<comments>http://mituzas.lt/2009/02/06/charsets-mutex-meets-innodb/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 13:07:48 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[charsets]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=326</guid>
		<description><![CDATA[When InnoDB compares data (like, when looking up in indexes), it actually asks help from MySQL &#8211; character sets may provide different rules for evaluation. MySQL then looks up character set information. This is where the fun begins &#8211; if &#8230; <a href="http://mituzas.lt/2009/02/06/charsets-mutex-meets-innodb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When InnoDB compares data (like, when looking up in indexes), it actually asks help from MySQL &#8211; character sets may provide different rules for evaluation. MySQL then looks up character set information. This is where the fun begins &#8211; if character set used for comparison is default server character set, or latin1 &#8211; there are shortcuts. If not (say, some smart developer decided to use Unicode without forcing DBA to set default server charset, as it isn&#8217;t needed) &#8211; a very nice internal routine is called, which at the very beginning does exactly this:</p>
<pre>
 /*
    To make things thread safe we are not
    allowing other threads to interfere
    while we may changing the cs_info_table
  */
  pthread_mutex_lock(&#038;THR_LOCK_charset);
</pre>
<p>Apparently, ha_innodb.cc has such comment too:</p>
<pre>
/* Use the charset number to pick the right charset struct for
the comparison. Since the MySQL function get_charset may be
slow before Bar removes the mutex operation there, we first
look at 2 common charsets directly. */

if (charset_number == default_charset_info->number) {
    charset = default_charset_info;
} else if (charset_number == my_charset_latin1.number) {
    charset = &#038;my_charset_latin1;
} else {
    charset = get_charset(charset_number, MYF(MY_WME));
    [...]
</pre>
<p>I&#8217;ll avoid going into discussions why such global lock at every row operation is harmful, but in case anyone is hitting lots of mutex contention there &#8211; just set default server character set to what your databases are in (or use binary or latin1, or add a clause for utf8 up here, or remove mutex, nobody is changing your character sets anyway ;-) </p>
<p><b> Update:</b> Some of the discussion is at <a href='http://bugs.mysql.com/bug.php?id=42649'>bug#42649</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mituzas.lt/2009/02/06/charsets-mutex-meets-innodb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
