<?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: Case-insensitive validates_uniqueness_of slowness</title>
	<atom:link href="http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/</link>
	<description>Our latest geek adventures!</description>
	<lastBuildDate>Tue, 16 Mar 2010 19:42:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ennuyer.net &#187; Blog Archive &#187; Rails Reading - November 24, 2009</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-921</link>
		<dc:creator>Ennuyer.net &#187; Blog Archive &#187; Rails Reading - November 24, 2009</dc:creator>
		<pubDate>Tue, 24 Nov 2009 22:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-921</guid>
		<description>[...]  Case-insensitive validates_uniqueness_of slowness &#124; Floorplanner Tech Blog  [...]</description>
		<content:encoded><![CDATA[<p>[...]  Case-insensitive validates_uniqueness_of slowness | Floorplanner Tech Blog  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Willem van Bergen</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-880</link>
		<dc:creator>Willem van Bergen</dc:creator>
		<pubDate>Fri, 20 Nov 2009 06:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-880</guid>
		<description>Yes, the &lt;code&gt;LOWER&lt;/code&gt; function makes that MySQL cannot use the index on the column anymore. Unfortunately, MySQL does not support indices on expressions like PostgreSQL does.</description>
		<content:encoded><![CDATA[<p>Yes, the <code>LOWER</code> function makes that MySQL cannot use the index on the column anymore. Unfortunately, MySQL does not support indices on expressions like PostgreSQL does.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Johnson</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-874</link>
		<dc:creator>Scott Johnson</dc:creator>
		<pubDate>Thu, 19 Nov 2009 21:05:41 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-874</guid>
		<description>Thanks, I understand better now. In my case I want :case_sensitive =&gt; true, and the default Rails-generated query seems to work fine (EXPLAIN shows it using the index).</description>
		<content:encoded><![CDATA[<p>Thanks, I understand better now. In my case I want :case_sensitive =&gt; true, and the default Rails-generated query seems to work fine (EXPLAIN shows it using the index).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Willem van Bergen</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-866</link>
		<dc:creator>Willem van Bergen</dc:creator>
		<pubDate>Thu, 19 Nov 2009 05:34:42 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-866</guid>
		<description>I just tested what queries are issued when using different values for the &lt;code&gt;:case_sensitive&lt;/code&gt; option of &lt;code&gt;validates_uniqueness_of&lt;/code&gt;:

&lt;pre lang=&quot;sql&quot;&gt;
# :case_sensitive =&gt; false
SELECT `users`.id FROM `users` 
 WHERE (LOWER(`users`.`email`) = BINARY &#039;test@example.com&#039;) LIMIT 1

# :case_sensitive =&gt; true
SELECT `users`.id FROM `users` 
 WHERE (`users`.`email` = BINARY &#039;test@example.com&#039;) LIMIT 1

# without :case_sensitive option
SELECT `users`.id FROM `users` 
 WHERE (`users`.`email` = BINARY &#039;test@example.com&#039;) LIMIT 1
&lt;/pre&gt;

Rails always uses the &lt;code&gt;BINARY&lt;/code&gt; keyword in the queries it issues to make the check case sensitive, regardless of the collation. That&#039;s why I really need &lt;code&gt;:case_sensitive =&gt; false&lt;/code&gt; for a case insensitive check, which uses the horribly inefficient query.

So unfortunately, this custom implementation really is needed to make sure the index on the field is used.

BTW: I changed a &lt;code&gt;:case_sensitive =&gt; true&lt;/code&gt; into &lt;code&gt;:case_sensitive =&gt; false&lt;/code&gt;. Thanks for spotting the mistake!</description>
		<content:encoded><![CDATA[<p>I just tested what queries are issued when using different values for the <code>:case_sensitive</code> option of <code>validates_uniqueness_of</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #808080; font-style: italic;"># :case_sensitive =&gt; false</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`users`</span> 
 <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span>LOWER<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`email`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">BINARY</span> <span style="color: #ff0000;">'test@example.com'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># :case_sensitive =&gt; true</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`users`</span> 
 <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`email`</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">BINARY</span> <span style="color: #ff0000;">'test@example.com'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># without :case_sensitive option</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`users`</span> 
 <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`users`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`email`</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">BINARY</span> <span style="color: #ff0000;">'test@example.com'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span></pre></div></div>

<p>Rails always uses the <code>BINARY</code> keyword in the queries it issues to make the check case sensitive, regardless of the collation. That&#8217;s why I really need <code>:case_sensitive =&gt; false</code> for a case insensitive check, which uses the horribly inefficient query.</p>
<p>So unfortunately, this custom implementation really is needed to make sure the index on the field is used.</p>
<p>BTW: I changed a <code>:case_sensitive => true</code> into <code>:case_sensitive => false</code>. Thanks for spotting the mistake!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Johnson</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-865</link>
		<dc:creator>Scott Johnson</dc:creator>
		<pubDate>Thu, 19 Nov 2009 01:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-865</guid>
		<description>Or is that :case_sensitive =&gt; false. I think your post mixes them up just as I have.</description>
		<content:encoded><![CDATA[<p>Or is that :case_sensitive =&gt; false. I think your post mixes them up just as I have.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Johnson</title>
		<link>http://techblog.floorplanner.com/2009/11/17/case-insensitive-validates_uniqueness_of-slowness/comment-page-1/#comment-864</link>
		<dc:creator>Scott Johnson</dc:creator>
		<pubDate>Thu, 19 Nov 2009 01:10:33 +0000</pubDate>
		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=787#comment-864</guid>
		<description>Umm... why not just leave off the :case_sensitive =&gt; true?</description>
		<content:encoded><![CDATA[<p>Umm&#8230; why not just leave off the :case_sensitive =&gt; true?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
