<?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: On partial indexes for string columns</title>
	<atom:link href="http://openquery.com/blog/partial-indexes-string-columns/feed" rel="self" type="application/rss+xml" />
	<link>http://openquery.com/blog/partial-indexes-string-columns</link>
	<description>About MySQL, Drizzle, MariaDB and more!</description>
	<lastBuildDate>Mon, 19 Mar 2012 14:26:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Fernando Ipar</title>
		<link>http://openquery.com/blog/partial-indexes-string-columns/comment-page-1#comment-1645</link>
		<dc:creator>Fernando Ipar</dc:creator>
		<pubDate>Fri, 14 Aug 2009 12:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://openquery.com/blog/?p=895#comment-1645</guid>
		<description>That&#039;s a great use of the reverse function, I never thought of it :)

As for the full index, you had me testing that query for a while until I realized it only uses the index if you only project that very field, i.e., your very specific query is the one that uses the index (select  from table where  LIKE &#039;%string%&#039;). 

Of course, it still needs to process all of the tuples (if I don&#039;t misunderstand explains output, and I hope I don&#039;t since I don&#039;t think there&#039;s a way for any database to optimize those kind of queries unless we go for something like a FULLTEXT index, or move it out of the database altogether with Sphinx or Lucene), but doing it with an index is certainly more efficient. 

Now, in order to take advantage of this index while projecting other columns from the result, this is all I came up with (I had to change the example because I already had data on this table): 

mysql&gt; explain select * from tasks where city in (select city from tasks where city like &#039;%fi%&#039;)\G
*************************** 1. row ***************************
           id: 1
  select_type: PRIMARY
        table: tasks
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 150000
        Extra: Using where
*************************** 2. row ***************************
           id: 2
  select_type: DEPENDENT SUBQUERY
        table: tasks
         type: index_subquery
possible_keys: city,idx_full_city
          key: city
      key_len: 253
          ref: func
         rows: 1
        Extra: Using index; Using where
2 rows in set (0.00 sec)

What do you think? Is it any use? Is there a better way? :)

Regards</description>
		<content:encoded><![CDATA[<p>That&#8217;s a great use of the reverse function, I never thought of it <img src='http://openquery.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As for the full index, you had me testing that query for a while until I realized it only uses the index if you only project that very field, i.e., your very specific query is the one that uses the index (select  from table where  LIKE &#8216;%string%&#8217;). </p>
<p>Of course, it still needs to process all of the tuples (if I don&#8217;t misunderstand explains output, and I hope I don&#8217;t since I don&#8217;t think there&#8217;s a way for any database to optimize those kind of queries unless we go for something like a FULLTEXT index, or move it out of the database altogether with Sphinx or Lucene), but doing it with an index is certainly more efficient. </p>
<p>Now, in order to take advantage of this index while projecting other columns from the result, this is all I came up with (I had to change the example because I already had data on this table): </p>
<p>mysql&gt; explain select * from tasks where city in (select city from tasks where city like &#8216;%fi%&#8217;)\G<br />
*************************** 1. row ***************************<br />
           id: 1<br />
  select_type: PRIMARY<br />
        table: tasks<br />
         type: ALL<br />
possible_keys: NULL<br />
          key: NULL<br />
      key_len: NULL<br />
          ref: NULL<br />
         rows: 150000<br />
        Extra: Using where<br />
*************************** 2. row ***************************<br />
           id: 2<br />
  select_type: DEPENDENT SUBQUERY<br />
        table: tasks<br />
         type: index_subquery<br />
possible_keys: city,idx_full_city<br />
          key: city<br />
      key_len: 253<br />
          ref: func<br />
         rows: 1<br />
        Extra: Using index; Using where<br />
2 rows in set (0.00 sec)</p>
<p>What do you think? Is it any use? Is there a better way? <img src='http://openquery.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Regards</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
