<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ukesh's Weblog</title>
	<atom:link href="http://ukesh.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ukesh.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 03 Mar 2011 07:47:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ukesh.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ukesh's Weblog</title>
		<link>http://ukesh.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ukesh.wordpress.com/osd.xml" title="Ukesh&#039;s Weblog" />
	<atom:link rel='hub' href='http://ukesh.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Basic git commands</title>
		<link>http://ukesh.wordpress.com/2010/11/26/basic-git-commands/</link>
		<comments>http://ukesh.wordpress.com/2010/11/26/basic-git-commands/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 06:35:37 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[basic git]]></category>
		<category><![CDATA[basic git commands]]></category>
		<category><![CDATA[git commands]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=31</guid>
		<description><![CDATA[Need to do an initial commit: mkdir dir_name cd dir_name git init git add . git commit Repository cloning: git clone repository_url Add a file: git add file_path What are the things you modified and added locally git status Commit the files: git commit git pull git push origin master(after commit need to push the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=31&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Need to do an initial commit:<br />
  mkdir dir_name<br />
  cd dir_name<br />
  git init<br />
  git add .<br />
  git commit</p>
<p>Repository cloning:<br />
  git clone repository_url</p>
<p>Add a file:<br />
  git add file_path</p>
<p>What are the things you modified and added locally<br />
  git status</p>
<p>Commit the files:<br />
  git commit</p>
<p>  git pull<br />
  git push origin master(after commit need to push the files)</p>
<p>Need to see the commits<br />
  git log</p>
<p>Delete a Remote Branch from GitHub<br />
 git push origin :branch_name</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=31&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2010/11/26/basic-git-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Browse Button with css style</title>
		<link>http://ukesh.wordpress.com/2010/10/12/browse-button-with-css-style/</link>
		<comments>http://ukesh.wordpress.com/2010/10/12/browse-button-with-css-style/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 10:08:32 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[browse button style]]></category>
		<category><![CDATA[browse button with style]]></category>
		<category><![CDATA[file field with style]]></category>
		<category><![CDATA[stylish browse button]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=26</guid>
		<description><![CDATA[Hi All, Here i have create a simple HTML file with the browse button(added some css style). &#60;html&#62; &#60;head&#62; &#60;style&#62; #filefield { position:relative; } #show_filefield { position: absolute; top: 0px; left: 0px; z-index: 1; background:url(images.jpeg) 100% 0px no-repeat; height:26px; width:240px; } #upload_field { width:155px; height:26px; margin-right:85px; font-size:16px; border:solid 1px #000; } #hide_filefield { position:relative; width:240px; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=26&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi All,</p>
<p>Here i have create a simple HTML file with the browse button(added some css style).</p>
<p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;style&gt;<br />
#filefield {<br />
position:relative;<br />
}</p>
<p>#show_filefield {<br />
position: absolute;<br />
top: 0px;<br />
left: 0px;<br />
z-index: 1;<br />
background:url(images.jpeg) 100% 0px no-repeat;<br />
height:26px;<br />
width:240px;<br />
}</p>
<p>#upload_field {<br />
width:155px;<br />
height:26px;<br />
margin-right:85px;<br />
font-size:16px;<br />
border:solid 1px #000;<br />
}</p>
<p>#hide_filefield {<br />
position:relative;<br />
width:240px;<br />
height:26px;<br />
text-align: right;<br />
-moz-opacity:0 ;<br />
filter:alpha(opacity: 0);<br />
opacity: 0;<br />
z-index: 2;<br />
}<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&#8221;filefield&#8221;&gt;<br />
&lt;input type=&#8221;file&#8221; size=&#8221;24&#8243; id=&#8221;hide_filefield&#8221; onchange=&#8221;getElementById(&#8216;upload_field&#8217;).value = getElementById(&#8216;hide_filefield&#8217;).value;&#8221; /&gt;<br />
&lt;div id=&#8221;show_filefield&#8221;&gt;&lt;input type=&#8221;text&#8221; id=&#8221;upload_field&#8221; /&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>&nbsp;</p>
<p>Thanks</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=26&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2010/10/12/browse-button-with-css-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular Expression</title>
		<link>http://ukesh.wordpress.com/2010/09/16/regular-expression/</link>
		<comments>http://ukesh.wordpress.com/2010/09/16/regular-expression/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 09:42:32 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[regular expression for]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=23</guid>
		<description><![CDATA[Only String = /^[a-zA-Z]+$/ ex: &#8220;Therock&#8221; Only Digits = /^\d+$/ ex: &#8220;3215&#8243; Alphanumeric and underscore = /^\w+$/ or /^[a-zA-Z0-9\_]+$/ ex: address,address_1 Email = /^[\w\.]+@\w+\.[a-z]{1,3}$/ ex: rails@gmail.com, rails_get@gmail.com Mobile Number(starts with &#8216;+&#8217; and only 12 digits) = /^\+\s\d{12}$/ ex: +919999988888 Get left side value ex: &#8220;ukesh kumar&#8221;.scan(/(.*)\s/).flatten.to_s Get right side value ex: &#8220;ukesh kumar&#8221;.scan(/\s(.*)/).flatten.to_s Standard Username/login [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=23&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Only String = /^[a-zA-Z]+$/<br />
ex: &#8220;Therock&#8221;</p>
<p>Only Digits = /^\d+$/<br />
ex: &#8220;3215&#8243;</p>
<p>Alphanumeric and underscore = /^\w+$/ or /^[a-zA-Z0-9\_]+$/<br />
ex: address,address_1</p>
<p>Email = /^[\w\.]+@\w+\.[a-z]{1,3}$/<br />
ex: rails@gmail.com, rails_get@gmail.com</p>
<p>Mobile Number(starts with &#8216;+&#8217; and only 12 digits) = /^\+\s\d{12}$/<br />
ex: +919999988888</p>
<p>Get left side value<br />
ex: &#8220;ukesh kumar&#8221;.scan(/(.*)\s/).flatten.to_s</p>
<p>Get right side value<br />
ex: &#8220;ukesh kumar&#8221;.scan(/\s(.*)/).flatten.to_s</p>
<p>Standard Username/login = /^\w[\w\.+\-_@ ]+$/<br />
ex: ukesh86, uk.esh</p>
<div id="_mcePaste" class="mcePaste" style="position:absolute;left:-10000px;top:105px;width:1px;height:1px;overflow:hidden;">Get left side value<br />
ex: &#8220;ukesh kumar&#8221;.s</p>
<p>Get right side value<br />
ex: &#8220;ukesh kumar&#8221;.s</p>
<p>Standard Username<br />
ex: ukesh86, uk.esh</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=23&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2010/09/16/regular-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Regular Expression to get alpha-numeric values in an Array</title>
		<link>http://ukesh.wordpress.com/2010/09/16/using-regular-expression-to-get-alpha-numeric-values-in-an-array/</link>
		<comments>http://ukesh.wordpress.com/2010/09/16/using-regular-expression-to-get-alpha-numeric-values-in-an-array/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 04:38:44 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[how to get alphanumeric value in array]]></category>
		<category><![CDATA[regular expression in array]]></category>
		<category><![CDATA[using regexp in an array]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=18</guid>
		<description><![CDATA[&#62;&#62; a = %w{a m 1 4 @ ) *} =&#62; ["a", "m", "1", "4", "@", ")", "*"] &#62;&#62; a.select{&#124;x&#124; x =~ /\w/} =&#62; ["a", "m", "1", "4"]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=18&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&gt;&gt; a = %w{a m 1 4 @ ) *}<br />
=&gt; ["a", "m", "1", "4", "@", ")", "*"]<br />
&gt;&gt; a.select{|x| x =~ /\w/}<br />
=&gt; ["a", "m", "1", "4"]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=18&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2010/09/16/using-regular-expression-to-get-alpha-numeric-values-in-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Components of a Time</title>
		<link>http://ukesh.wordpress.com/2010/05/25/components-of-a-time/</link>
		<comments>http://ukesh.wordpress.com/2010/05/25/components-of-a-time/#comments</comments>
		<pubDate>Tue, 25 May 2010 04:17:47 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ruby time]]></category>
		<category><![CDATA[time now]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=12</guid>
		<description><![CDATA[require &#8216;rubygems&#8217; time = Time.new # Components of a Time puts &#8220;Current Time : &#8221; + time.inspect puts time.year    # =&#62; Year of the date puts time.month   # =&#62; Month of the date (1 to 12) puts time.day     # =&#62; Day of the date (1 to 31 ) puts time.wday    # =&#62; 0: Day of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=12&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>require &#8216;rubygems&#8217;</p>
<p>time = Time.new</p>
<p># Components of a Time<br />
puts &#8220;Current Time : &#8221; + time.inspect<br />
puts time.year    # =&gt; Year of the date<br />
puts time.month   # =&gt; Month of the date (1 to 12)<br />
puts time.day     # =&gt; Day of the date (1 to 31 )<br />
puts time.wday    # =&gt; 0: Day of week: 0 is Sunday<br />
puts time.yday    # =&gt; 365: Day of year<br />
puts time.hour    # =&gt; 23: 24-hour clock<br />
puts time.min     # =&gt; 59<br />
puts time.sec     # =&gt; 59<br />
puts time.usec    # =&gt; 999999: microseconds<br />
puts time.zone    # =&gt; &#8220;UTC&#8221;: timezone name</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=12&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2010/05/25/components-of-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>acts_as_taggable</title>
		<link>http://ukesh.wordpress.com/2008/04/18/acts_as_taggable/</link>
		<comments>http://ukesh.wordpress.com/2008/04/18/acts_as_taggable/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 09:58:50 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=10</guid>
		<description><![CDATA[The acts_as_taggable(plugin), although built in to Rails, is basically deprecated. And the gem version is old and requires a separate join table for every taggable model, which is silly . update Please see the updated has_many_polymorphs documentation, which has instructions for using the new, built-in tagging generator. install Uninstall whatever acts_as_taggable version you have, to prevent [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=10&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The acts_as_taggable(plugin)<a href="http://wiki.rubyonrails.com/rails/pages/ActsAsTaggablePluginHowto"></a>, although built in to Rails, is basically <a href="http://www.ruby-forum.com/topic/89480">deprecated</a>. And the  gem version is old and requires a separate join table for every taggable model, which is silly       .</p>
<h2>update</h2>
<p>Please see the updated <a href="http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/">has_many_polymorphs documentation</a>, which has instructions for using the new, built-in tagging generator.</p>
<h2>install</h2>
<p>Uninstall whatever <code>acts_as_taggable</code> version you have, to prevent fighting among the plugins. Then, install <code>has_many_polymorphs</code>:</p>
<div class="typocode">
<pre><code>script/plugin install -x svn://rubyforge.org/var/svn/fauna/has_many_polymorphs/trunk</code></pre>
</div>
<h2>models</h2>
<p>We will assume you are using the default <code>acts_as_taggable</code> models. You should have a Tag model, with a <code>name</code> field, as well as a Taggings join model. However, these models are part of the <code>acts_as_taggable</code> plugin source, whereas their migrations have to be part of your app (which is confusing). Instead, with <code>has_many_polymorphs</code>, we have to make the models part of the app, too:</p>
<div class="typocode">
<pre><code>class Tag &lt; ActiveRecord::Base
has_many_polymorphs :taggables,
:from =&gt; [:books, :magazines],
:through =&gt; :taggings,
:dependent =&gt; :destroy
end

class Tagging &lt; ActiveRecord::Base
belongs_to :tag
belongs_to :taggable, :polymorphic =&gt; true

def before_destroy
# disallow orphaned tags
tag.destroy_without_callbacks if tag.taggings.count &lt; 2
end
end</code></pre>
</div>
<p>See the line <code>[:books, :magazines]</code>? This line replaces all the <code>acts_as_taggable</code> macro calls strewn through your models. Simply list in the array the models that you want to be able to tag. (You can even tag Tags, see below.)</p>
<h2>migrations</h2>
<p>We need to make sure your existing tag schema fits this. It should be something like:</p>
<div class="typocode">
<pre><code>class AddTagSupport &lt; ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.column :name, :string, :null =&gt; false
end
add_index :tags, :name, :unique =&gt; true

create_table :taggings do |t|
t.column :tag_id, :integer, :null =&gt; false
t.column :taggable_id, :integer, :null =&gt; false
t.column :taggable_type, :string, :null =&gt; false
end
add_index :taggings, [:tag_id, :taggable_id, :taggable_type], :unique =&gt; true
end

def self.down
drop_table :tags
drop_table :taggings
end
end</code></pre>
</div>
<p>If your schema isn’t like this already, you have two choices. You can add more options to the association macros in your models, to show them how to relate to your schema, or you can write a migration to convert your schema into canonical form. The first option is possibly quicker to implement, but the second one will be easier to maintain.</p>
<h2>api</h2>
<p>Hey, you’re done! Well, not really. The <span class="caps">API</span> is different, which is the biggest sticking point. We’ll write some convenience methods to mimic the old way. You should put the methods in <code>RAILS_ROOT/lib/tag_extensions.rb</code> or similar.</p>
<div class="typocode">
<pre><code>class ActiveRecord::Base
def tag_with tags
tags.split(" ").each do |tag|
Tag.find_or_create_by_name(tag).taggables &lt;&lt; self
end
end

def tag_list
tags.map(&amp;:name).join(' ')
end
end</code></pre>
</div>
<p>Pretty straightforward, which makes it easy to modify. For example, to make creating a model from <code>params</code> more transparent, we could add:</p>
<div class="typocode">
<pre><code>alias :tags= :tag_with</code></pre>
</div>
<p>Or to enforce lowercase tags, just do:</p>
<div class="typocode">
<pre><code>def tag_with tags
tags.downcase.split(" ").each do |tag|
Tag.find_or_create_by_name(tag).taggables &lt;&lt; self
end
end</code></pre>
</div>
<p>If you want to allow tags with spaces in them, we can accept an array instead of a string:</p>
<div class="typocode">
<pre><code>def tag_with *tags
tags.flatten.each do |tag|
Tag.find_or_create_by_name(tag).taggables &lt;&lt; self
end
end</code></pre>
</div>
<p>To delete tags (don’t forget to <code>downcase</code> the <code>tag_string</code> if you need to):</p>
<div class="typocode">
<pre><code>def tag_delete tag_string
split = tag_string.split(" ")
tags.delete tags.select{|t| split.include? t.name}
end</code></pre>
</div>
<p>To get all models for a tag (and all in a single <span class="caps">SQL</span> query, thanks to the plugin):</p>
<div class="typocode">
<pre><code>Tag.find_by_name("artichoke").taggables</code></pre>
</div>
<p>To get only a specific model for a tag:</p>
<div class="typocode">
<pre><code>Tag.find_by_name("artichoke").books</code></pre>
</div>
<p>Easy and powerful. And if you need to find which tags are most popular, see <a href="http://blog.evanweaver.com/articles/2007/02/09/how-to-find-the-most-popular-tags">here</a>.</p>
<p>Make sure that you <code>require</code> the file containing your <span class="caps">API</span> methods in <code>environment.rb</code>, since Rails won’t load it automatically:</p>
<div class="typocode">
<pre><code>require 'tag_extensions'</code></pre>
</div>
<h2>performance note</h2>
<p>It is more efficient if we add <code>:skip_duplicates =&gt; false</code> to the <code>has_many_polymorphs :taggables</code> call. Then the <code>taggables</code> for each Tag won’t get loaded at all during the <code>&lt;&lt;</code>, because there is no reason to check them.</p>
<p>If we do this, though, and use database constraints to enforce uniqueness, we need to manually <code>rescue</code> assignment errors in our <code>tag_with</code> method:</p>
<div class="typocode">
<pre><code>def tag_with tags
tags.split(" ").each do |tag|
begin
Tag.find_or_create_by_name(tag).taggables &lt;&lt; self
rescue ActiveRecord::StatementInvalid =&gt; e
raise unless e.to_s[/Duplicate entry/]
end
end
end</code></pre>
</div>
<h2>self-referential tagging</h2>
<p>What if you want to be able to tag tags? This is more useful than might first appear. It lets you create an ad-hoc non-exclusive hierarchy of categories without extra models. This is much more maintainable than one based on hard-coded models for each level. But you need some way to distinguish “the tags tagged by a tag” and “the tags a tag is tagged by”—a directed graph. So we will rename the parent relationship:</p>
<div class="typocode">
<pre><code>class Tag &lt; ActiveRecord::Base
has_many_polymorphs :taggables,
:from =&gt; [:books, :magazines, :tags],
:through =&gt; :taggings,
:dependent =&gt; :destroy,
:as =&gt; :tagger
end

class Tagging &lt; ActiveRecord::Base
belongs_to :tagger,
:class_name =&gt; "Tag",
:foreign_key =&gt; "tagger_id"
belongs_to :taggable,
:polymorphic =&gt; true
end</code></pre>
</div>
<p>Modify the migration accordingly. Now, you can use <code>some_tag.taggables</code> to get the targets of <code>some_tag</code>, and <code>some_tag.taggers</code> to get the tags for which <code>some_tag</code> is itself a target.</p>
<p>Note that your <code>tag_delete</code> method might have to be more longwinded due to <a href="http://dev.rubyonrails.org/ticket/6466">this</a> long-outstanding Rails bug.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ukesh.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ukesh.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=10&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2008/04/18/acts_as_taggable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Index Merge Optimization</title>
		<link>http://ukesh.wordpress.com/2008/04/11/index-merge-optimization/</link>
		<comments>http://ukesh.wordpress.com/2008/04/11/index-merge-optimization/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 09:25:29 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=5</guid>
		<description><![CDATA[The Index Merge method is used to retrieve rows with several range scans and to merge their results into one. The merge can produce unions, intersections, or unions-of-intersections of its underlying scans. This access method merges index scans from a single table; it does not merge scans across multiple tables. Note If you have upgraded [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=5&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <em>Index Merge</em> method is used to         retrieve rows with several <code>range</code> scans and to         merge their results into one. The merge can produce unions,         intersections, or unions-of-intersections of its underlying         scans. This access method merges index scans from a single         table; it does not merge scans across multiple tables.</p>
<div class="note" style="margin-left:0.5in;margin-right:0.5in;">
<h3 class="title">Note</h3>
<p>If you have upgraded from a previous version of MySQL, you           should be aware that this type of join optimization is first           introduced in MySQL 5.0, and represents a significant change           in behavior with regard to indexes. (Formerly, MySQL was able           to use at most only one index for each referenced table.)</p>
</div>
<p>In <code>EXPLAIN</code> output, the Index Merge method         appears as <code>index_merge</code> in the         <code>type</code> column. In this case, the         <code>key</code> column contains a list of indexes used,         and <code>key_len</code> contains a list of the longest         key parts for those indexes.</p>
<p>Examples:</p>
<pre>SELECT * FROM <em><code>tbl_name</code></em> WHERE <em><code>key1</code></em> = 10 OR <em><code>key2</code></em> = 20;

SELECT * FROM <em><code>tbl_name</code></em>
WHERE (<em><code>key1</code></em> = 10 OR <em><code>key2</code></em> = 20) AND <em><code>non_key</code></em>=30;

SELECT * FROM t1, t2
WHERE (t1.<em><code>key1</code></em> IN (1,2) OR t1.<em><code>key2</code></em> LIKE '<em><code>value</code></em>%')
AND t2.<em><code>key1</code></em>=t1.<em><code>some_col</code></em>;

SELECT * FROM t1, t2
WHERE t1.<em><code>key1</code></em>=1
AND (t2.<em><code>key1</code></em>=t1.<em><code>some_col</code></em> OR t2.<em><code>key2</code></em>=t1.<em><code>some_col2</code></em>);</pre>
<p>The Index Merge method has several access algorithms (seen in         the <code>Extra</code> field of <code>EXPLAIN</code> output):</p>
<div class="itemizedlist">
<ul>
<li><code>Using intersect(...)</code></li>
<li><code>Using union(...)</code></li>
<li><code>Using sort_union(...)</code></li>
</ul>
</div>
<p>The following sections describe these methods in greater detail.</p>
<div class="note" style="margin-left:0.5in;margin-right:0.5in;">
<h3 class="title">Note</h3>
<p>The Index Merge optimization algorithm has the following known           deficiencies:</p>
</div>
<div class="itemizedlist">
<ul>
<li>If a range scan is possible on some key, the optimizer will             not consider using Index Merge Union or Index Merge             Sort-Union algorithms. For example, consider this query:
<pre>SELECT * FROM t1 WHERE (goodkey1 &lt; 10 OR goodkey2 &lt; 20) AND badkey &lt; 30;</pre>
<p>For this query, two plans are possible:</p>
<div class="itemizedlist">
<ul>
<li>An Index Merge scan using the <code>(goodkey1 &lt; 10                 OR goodkey2 &lt; 20)</code> condition.</li>
<li>A range scan using the <code>badkey &lt; 30</code> condition.</li>
</ul>
</div>
<p>However, the optimizer considers only the second plan.</li>
<li>If your query has a complex <code>WHERE</code> clause             with deep             <a href="http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_and"><code>AND</code></a>/<a href="http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_or"><code>OR</code></a> nesting and MySQL doesn&#8217;t choose the optimal plan, try             distributing terms using the following identity laws:
<pre>(<em><code>x</code></em> AND <em><code>y</code></em>) OR <em><code>z</code></em> = (<em><code>x</code></em> OR <em><code>z</code></em>) AND (<em><code>y</code></em> OR <em><code>z</code></em>)
(<em><code>x</code></em> OR <em><code>y</code></em>) AND <em><code>z</code></em> = (<em><code>x</code></em> AND <em><code>z</code></em>) OR (<em><code>y</code></em> AND <em><code>z</code></em>)</pre>
</li>
<li>Index Merge is not applicable to fulltext indexes. We plan             to extend it to cover these in a future MySQL release.</li>
</ul>
</div>
<p>The choice between different possible variants of the Index         Merge access method and other access methods is based on cost         estimates of various available options.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ukesh.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ukesh.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=5&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2008/04/11/index-merge-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>How MySQL Uses Indexes</title>
		<link>http://ukesh.wordpress.com/2008/04/11/how-mysql-uses-indexes/</link>
		<comments>http://ukesh.wordpress.com/2008/04/11/how-mysql-uses-indexes/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 09:22:00 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=4</guid>
		<description><![CDATA[Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=4&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Indexes are used to find rows with specific column values         quickly. Without an index, MySQL must begin with the first row         and then read through the entire table to find the relevant         rows. The larger the table, the more this costs. If the table         has an index for the columns in question, MySQL can quickly         determine the position to seek to in the middle of the data file         without having to look at all the data. If a table has 1,000         rows, this is at least 100 times faster than reading         sequentially. If you need to access most of the rows, it is         faster to read sequentially, because this minimizes disk seeks.</p>
<p>Most MySQL indexes (<code>PRIMARY KEY</code>,         <code>UNIQUE</code>, <code>INDEX</code>, and         <code>FULLTEXT</code>) are stored in B-trees. Exceptions         are that indexes on spatial data types use R-trees, and that         <code>MEMORY</code> tables also support hash indexes.</p>
<p>Strings are automatically prefix- and end-space compressed.</p>
<p>In general, indexes are used as described in the following         discussion. Characteristics specific to hash indexes (as used in         <code>MEMORY</code> tables) are described at the end of         this section.</p>
<p>MySQL uses indexes for these operations:</p>
<div class="itemizedlist">
<ul>
<li>To find the rows matching a <code>WHERE</code> clause             quickly.</li>
<li>To eliminate rows from consideration. If there is a choice             between multiple indexes, MySQL normally uses the index that             finds the smallest number of rows.</li>
<li>To retrieve rows from other tables when performing joins.             MySQL can use indexes on columns more efficiently if they             are declared as the same type and size. In this context,             <code>VARCHAR</code> and <code>CHAR</code> are             considered the same if they are declared as the same size.             For example, <code>VARCHAR(10)</code> and             <code>CHAR(10)</code> are the same size, but             <code>VARCHAR(10)</code> and             <code>CHAR(15)</code> are not.
<p>Comparison of dissimilar columns may prevent use of indexes             if values cannot be compared directly without conversion.             Suppose that a numeric column is compared to a string             column. For a given value such as <code>1</code> in             the numeric column, it might compare equal to any number of             values in the string column such as <code>'1'</code>,             <code>' 1'</code>, <code>'00001'</code>, or             <code>'01.e1'</code>. This rules out use of any             indexes for the string column.</li>
<li>To find the <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_min"><code>MIN()</code></a> or             <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_max"><code>MAX()</code></a> value for a specific             indexed column <em><code>key_col</code></em>. This is             optimized by a preprocessor that checks whether you are             using <code>WHERE <em><code>key_part_N</code></em> =             <em><code>constant</code></em></code> on all key             parts that occur before <em><code>key_col</code></em> in the index. In this case, MySQL does a single key lookup             for each <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_min"><code>MIN()</code></a> or             <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_max"><code>MAX()</code></a> expression and             replaces it with a constant. If all expressions are replaced             with constants, the query returns at once. For example:
<pre>SELECT MIN(<em><code>key_part2</code></em>),MAX(<em><code>key_part2</code></em>)
FROM <em><code>tbl_name</code></em> WHERE <em><code>key_part1</code></em>=10;</pre>
</li>
<li>To sort or group a table if the sorting or grouping is done             on a leftmost prefix of a usable key (for example,             <code>ORDER BY <em><code>key_part1</code></em>,             <em><code>key_part2</code></em></code>). If all key             parts are followed by <code>DESC</code>, the key is             read in reverse order.</li>
<li>In some cases, a query can be optimized to retrieve values             without consulting the data rows. If a query uses only             columns from a table that are numeric and that form a             leftmost prefix for some key, the selected values may be             retrieved from the index tree for greater speed:
<pre>SELECT <em><code>key_part3</code></em> FROM <em><code>tbl_name</code></em>
WHERE <em><code>key_part1</code></em>=1</pre>
</li>
</ul>
</div>
<p>Suppose that you issue the following <code>SELECT</code> statement:</p>
<pre>mysql&gt; <strong><code>SELECT * FROM <em><code>tbl_name</code></em> WHERE col1=<em><code>val1</code></em> AND col2=<em><code>val2</code></em>;</code></strong></pre>
<p>If a multiple-column index exists on <code>col1</code> and         <code>col2</code>, the appropriate rows can be fetched         directly. If separate single-column indexes exist on         <code>col1</code> and <code>col2</code>, the         optimizer will attempt to use the Index Merge optimization or attempt to find         the most restrictive index by deciding which index finds fewer         rows and using that index to fetch the rows.</p>
<p><a class="indexterm" name="id3221404"></a><a class="indexterm" name="id3221416"></a></p>
<p>If the table has a multiple-column index, any leftmost prefix of         the index can be used by the optimizer to find rows. For         example, if you have a three-column index on <code>(col1,         col2, col3)</code>, you have indexed search capabilities on         <code>(col1)</code>, <code>(col1, col2)</code>, and         <code>(col1, col2, col3)</code>.</p>
<p>MySQL cannot use an index if the columns do not form a leftmost         prefix of the index. Suppose that you have the         <code>SELECT</code> statements shown here:</p>
<pre>SELECT * FROM <em><code>tbl_name</code></em> WHERE col1=<em><code>val1</code></em>;
SELECT * FROM <em><code>tbl_name</code></em> WHERE col1=<em><code>val1</code></em> AND col2=<em><code>val2</code></em>;

SELECT * FROM <em><code>tbl_name</code></em> WHERE col2=<em><code>val2</code></em>;
SELECT * FROM <em><code>tbl_name</code></em> WHERE col2=<em><code>val2</code></em> AND col3=<em><code>val3</code></em>;</pre>
<p>If an index exists on <code>(col1, col2, col3)</code>,         only the first two queries use the index. The third and fourth         queries do involve indexed columns, but         <code>(col2)</code> and <code>(col2, col3)</code> are not leftmost prefixes of <code>(col1, col2,         col3)</code>.</p>
<p><a class="indexterm" name="id3221544"></a><a class="indexterm" name="id3221557"></a><a class="indexterm" name="id3221569"></a><a class="indexterm" name="id3221582"></a></p>
<p>A B-tree index can be used for column comparisons in expressions         that use the         <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal"><code>=</code></a>,         <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_greater-than"><code>&gt;</code></a>,         <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_greater-than-or-equal"><code>&gt;=</code></a>,         <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_less-than"><code>&lt;</code></a>,         <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_less-than-or-equal"><code>&lt;=</code></a>,         or <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between"><code>BETWEEN</code></a> operators. The         index also can be used for         <a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like"><code>LIKE</code></a> comparisons if the         argument to <a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like"><code>LIKE</code></a> is a constant         string that does not start with a wildcard character. For         example, the following <code>SELECT</code> statements use         indexes:</p>
<pre>SELECT * FROM <em><code>tbl_name</code></em> WHERE <em><code>key_col</code></em> LIKE 'Patrick%';
SELECT * FROM <em><code>tbl_name</code></em> WHERE <em><code>key_col</code></em> LIKE 'Pat%_ck%';</pre>
<p>In the first statement, only rows with <code>'Patrick' &lt;=         <em><code>key_col</code></em> &lt; 'Patricl'</code> are         considered. In the second statement, only rows with         <code>'Pat' &lt;= <em><code>key_col</code></em> &lt;         'Pau'</code> are considered.</p>
<p>The following <code>SELECT</code> statements do not use         indexes:</p>
<pre>SELECT * FROM <em><code>tbl_name</code></em> WHERE <em><code>key_col</code></em> LIKE '%Patrick%';
SELECT * FROM <em><code>tbl_name</code></em> WHERE <em><code>key_col</code></em> LIKE <em><code>other_col</code></em>;</pre>
<p>In the first statement, the         <a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like"><code>LIKE</code></a> value begins with a         wildcard character. In the second statement, the         <a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like"><code>LIKE</code></a> value is not a constant.</p>
<p>If you use <code>... LIKE         '%<em><code>string</code></em>%'</code> and         <em><code>string</code></em> is longer than three         characters, MySQL uses the <em>Turbo Boyer-Moore         algorithm</em> to initialize the pattern for the string         and then uses this pattern to perform the search more quickly.</p>
<p><a class="indexterm" name="id3221794"></a><a class="indexterm" name="id3221806"></a></p>
<p>A search using <code><em><code>col_name</code></em> IS         NULL</code> employs indexes if         <em><code>col_name</code></em> is indexed.</p>
<p>Any index that does not span all         <a href="http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_and"><code>AND</code></a> levels in the         <code>WHERE</code> clause is not used to optimize the         query. In other words, to be able to use an index, a prefix of         the index must be used in every         <a href="http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_and"><code>AND</code></a> group.</p>
<p>The following <code>WHERE</code> clauses use indexes:</p>
<pre>... WHERE <em><code>index_part1</code></em>=1 AND <em><code>index_part2</code></em>=2 AND <em><code>other_column</code></em>=3
/* <em><code>index</code></em> = 1 OR <em><code>index</code></em> = 2 */
... WHERE <em><code>index</code></em>=1 OR A=10 AND <em><code>index</code></em>=2
/* optimized like "<em><code>index_part1</code></em>='hello'" */
... WHERE <em><code>index_part1</code></em>='hello' AND <em><code>index_part3</code></em>=5
/* Can use index on <em><code>index1</code></em> but not on <em><code>index2</code></em> or <em><code>index3</code></em> */
... WHERE <em><code>index1</code></em>=1 AND <em><code>index2</code></em>=2 OR <em><code>index1</code></em>=3 AND <em><code>index3</code></em>=3;</pre>
<p>These <code>WHERE</code> clauses do         <span class="emphasis"><em>not</em></span> use indexes:</p>
<pre>    /* <em><code>index_part1</code></em> is not used */
... WHERE <em><code>index_part2</code></em>=1 AND <em><code>index_part3</code></em>=2

/*  Index is not used in both parts of the WHERE clause  */
... WHERE <em><code>index</code></em>=1 OR A=10

/* No index spans all rows  */
... WHERE <em><code>index_part1</code></em>=1 OR <em><code>index_part2</code></em>=10</pre>
<p>Sometimes MySQL does not use an index, even if one is available.         One circumstance under which this occurs is when the optimizer         estimates that using the index would require MySQL to access a         very large percentage of the rows in the table. (In this case, a         table scan is likely to be much faster because it requires fewer         seeks.) However, if such a query uses <code>LIMIT</code> to retrieve only some of the rows, MySQL uses an index anyway,         because it can much more quickly find the few rows to return in         the result.</p>
<p>Hash indexes have somewhat different characteristics from those         just discussed:</p>
<div class="itemizedlist">
<ul>
<li>They are used only for equality comparisons that use the             <code>=</code> or <code>&lt;=&gt;</code> operators (but are <span class="emphasis"><em>very</em></span> fast). They are             not used for comparison operators such as             <code>&lt;</code> that find a range of values.</li>
<li>The optimizer cannot use a hash index to speed up             <code>ORDER BY</code> operations. (This type of index             cannot be used to search for the next entry in order.)</li>
<li>MySQL cannot determine approximately how many rows there are             between two values (this is used by the range optimizer to             decide which index to use). This may affect some queries if             you change a <code>MyISAM</code> table to a             hash-indexed <code>MEMORY</code> table.</li>
<li>Only whole keys can be used to search for a row. (With a             B-tree index, any leftmost prefix of the key can be used to             find rows.)</li>
</ul>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ukesh.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ukesh.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=4&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2008/04/11/how-mysql-uses-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby &#8211; unpack &amp; pack</title>
		<link>http://ukesh.wordpress.com/2008/03/04/ruby-unpack-pack/</link>
		<comments>http://ukesh.wordpress.com/2008/03/04/ruby-unpack-pack/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 12:46:07 +0000</pubDate>
		<dc:creator>ukesh</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[pack]]></category>
		<category><![CDATA[unpack]]></category>

		<guid isPermaLink="false">http://ukesh.wordpress.com/?p=3</guid>
		<description><![CDATA[Program: hal = &#8220;My Name is BILLA&#8221; ascii = hal.unpack(&#8220;C*&#8221;) # We can&#8217;t use Array#each since we can&#8217;t mutate a Fixnum ascii.collect! { &#124;i&#124; i + 6                         # add one to each ASCII value } ibm = ascii.pack(&#8220;C*&#8221;) puts ibm order=ibm.unpack(&#8220;C*&#8221;) order.collect! {&#124;x&#124; x-6 } re=order.pack(&#8220;C*&#8221;) puts re Output: Encrption method:   DUPLICATE &#8211;&#62;  S&#38;Tgsk&#38;oy&#38;HORRG [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=3&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Program:</p>
<p>hal = &#8220;My Name is BILLA&#8221;<br />
ascii = hal.unpack(&#8220;C*&#8221;)<br />
# We can&#8217;t use Array#each since we can&#8217;t mutate a Fixnum<br />
ascii.collect! { |i|<br />
i + 6                         # add one to each ASCII value<br />
}<br />
ibm = ascii.pack(&#8220;C*&#8221;)<br />
puts ibm</p>
<p>order=ibm.unpack(&#8220;C*&#8221;)<br />
order.collect! {|x| x-6 }<br />
re=order.pack(&#8220;C*&#8221;)</p>
<p>puts re</p>
<p>Output:</p>
<p>Encrption method:   DUPLICATE &#8211;&gt;  S&amp;Tgsk&amp;oy&amp;HORRG<br />
Decription method : ORIGINAL &#8211;&gt; My Name is BILLA</p>
<p>Regadrs,</p>
<p>UKESH</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ukesh.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ukesh.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ukesh.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ukesh.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ukesh.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ukesh.wordpress.com&amp;blog=3057039&amp;post=3&amp;subd=ukesh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ukesh.wordpress.com/2008/03/04/ruby-unpack-pack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a997e6d0677e8dcf452027559d6e3585?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ukesh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
