<?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>beer planet &#187; MySQL</title> <atom:link href="http://beerpla.net/category/mysql/feed/" rel="self" type="application/rss+xml" /><link>http://beerpla.net</link> <description>where things have nothing to do with beer - tutorials, tips, how-tos, thoughts, hacks, and other techy nonsense</description> <lastBuildDate>Fri, 06 Jan 2012 08:50:59 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel='hub' href='http://beerpla.net/?pushpress=hub'/> <item><title>How To Fix Intermittent MySQL Errcode 13 Errors On Windows</title><link>http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/</link> <comments>http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/#comments</comments> <pubDate>Tue, 05 Jan 2010 10:49:33 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[13]]></category> <category><![CDATA[errcode]]></category> <category><![CDATA[errcode 13]]></category> <category><![CDATA[error]]></category> <category><![CDATA[mcafee]]></category> <category><![CDATA[microsoft security essentials]]></category> <category><![CDATA[myd]]></category> <category><![CDATA[myi]]></category> <category><![CDATA[myisam]]></category> <category><![CDATA[windows]]></category> <category><![CDATA[Wordpress]]></category> <guid
isPermaLink="false">http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/</guid> <description><![CDATA[<p><img
style="margin: 0px 10px 10px 0px; display: inline" title="13" alt="13" align="left" src="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image.png" width="150" height="150" /></p><h2>The Problem</h2><p>I&#039;ve had MySQL on my Windows 7 laptop for a bit (as part of <a
href="http://www.wampserver.com/en/" rel="nofollow">wampserver</a>), mostly for local offline WordPress development.</p><p>However, even though MySQL is relatively stable, I&#039;ve been observing a vast quantity of intermittent MySQL errors, as reported by WordPress in the PHP error log (C:\wamp\logs\php_error.log). Here are some examples:</p><div
class="wp_syntax"><div
class="code"><pre>[05-Jan-2010 09:47:51] WordPress database error Error on delete of
'C:\Windows\TEMP\#sql17e0_1a2_6.MYD' (Errcode: 13) for query SELECT t.*, tt.*
FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id =
tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (3)
ORDER BY t.name ASC made by require, require_once, include, get_footer,
locate_template, load_template, require_once, dynamic_sidebar,</pre></div></div><p>...<div
class=clear></div> <a
href="http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p><img
style="margin: 0px 10px 10px 0px; display: inline" title="13" alt="13" align="left" src="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image.png" width="150" height="150" /></p><h2>The Problem</h2><p>I&#039;ve had MySQL on my Windows 7 laptop for a bit (as part of <a
href="http://www.wampserver.com/en/" rel="nofollow">wampserver</a>), mostly for local offline WordPress development.</p><p>However, even though MySQL is relatively stable, I&#039;ve been observing a vast quantity of intermittent MySQL errors, as reported by WordPress in the PHP error log (C:\wamp\logs\php_error.log). Here are some examples:</p><div
class="wp_syntax"><div
class="code"><pre>[05-Jan-2010 09:47:51] WordPress database error Error on delete of
'C:\Windows\TEMP\#sql17e0_1a2_6.MYD' (Errcode: 13) for query SELECT t.*, tt.*
FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id =
tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (3)
ORDER BY t.name ASC made by require, require_once, include, get_footer,
locate_template, load_template, require_once, dynamic_sidebar,
call_user_func_array, widget_rrm_recent_posts, RecentPosts-&amp;gt;execute,
ppl_expand_template, otf_categorylinks, get_the_category, wp_get_object_terms
&nbsp;
[05-Jan-2010 09:50:42] WordPress database error Error on delete of
'C:\Windows\TEMP\#sql17e0_1b0_0.MYD' (Errcode: 13) for query  SELECT
SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON
(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE 1=1  AND wp_term_taxonomy.taxonomy = 'category' AND
wp_term_taxonomy.term_id IN ('3') AND wp_posts.post_type = 'post' AND
(wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY
wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 made by require, wp,
WP-&amp;gt;main, WP-&amp;gt;query_posts, WP_Query-&amp;gt;query, WP_Query-&amp;gt;get_posts</pre></div></div><p>The important part here is &quot;Errcode: 13&quot;, which is a file access error. The MySQL daemon process (mysqld.exe) randomly cannot access temporary tables it itself creates, which causes these errors and failed queries.</p><h2>Digging Around</h2><p>After looking around and finding nothing obvious, I tracked down a few forum posts mentioning the same issue.</p><p>Here is the gist &#8211; the problem is caused by an anti-virus program that is clearly not working properly.</p><p>The one mentioned on the forums is McAfee (big surprise, right? McAfee is a piece of junk &#8211; probably the worst anti-virus I&#039;ve ever tried). In my case, however, it was the recently installed freeware security program from Microsoft called <a
href="http://www.microsoft.com/Security_Essentials/" rel="nofollow">Microsoft Security Essentials</a>, highly praised but problematic in this case nonetheless.</p><p>After thinking about it, I am confident that these security programs don&#039;t actually purposely prohibit access to the files MySQL creates. Instead, they lock these files for the duration of the check, so that the system doesn&#039;t get infected before they are approved. If you notice, the problems are related to temporary tables, created by MySQL on the fly. MySQL probably has a very short access timeout for these files, for performance reasons, and because it doesn&#039;t get this access fast enough, it considers it a failure (file deletions are failing, as you can see in the log).</p><h2>The Solution</h2><p>Now onto fixing the problem. The solution is to have Microsoft Security Essentials, in my case, or whatever your security program may be ignore these files.</p><p>You can block the whole Temp directory from being checked. It is not a good idea, as viruses can trickle down to that location and bypass your anti-virus:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image_3.png" class="lightview" rel="gallery['1313']" title="Ignore Windows Temp dir in Microsoft Security Essentials"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="Ignore Windows Temp dir in Microsoft Security Essentials" alt="Ignore Windows Temp dir in Microsoft Security Essentials" src="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image_thumb.png" width="700" height="545" /></a></p><p>Instead, you should just ignore by file extension: *.MYI and *.MYD. MySQL uses files with these extensions for its MyISAM table types. Using this approach is obviously safer as it doesn&#039;t single out a directory and instead targets specific files:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image_4.png" class="lightview" rel="gallery['1313']" title="Ignore *.MYI and *.MYD in Microsoft Security Essentials"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="Ignore *.MYI and *.MYD in Microsoft Security Essentials" alt="Ignore *.MYI and *.MYD in Microsoft Security Essentials" src="http://beerpla.net/wp-content/uploads/HowToFixIntermittentMySQLErrcode13Errors_1A77/image_thumb_3.png" width="700" height="545" /></a></p><p>After I applied either of these exclusions, all MySQL Error 13 problems went away immediately.</p><h2>Conclusion</h2><p>The intermittent Error 13 problem on Windows is caused by 2 otherwise legitimate processes which, when mixed together, end up breaking MySQL.</p><p>Is this entirely the fault of the antivirus programs? Inadvertently, perhaps so.</p><p>Could MySQL be a bit smarter in this scenario? Perhaps so as well.</p><p>What do you, MySQL pros, think?</p><div
class='post_blob_1'>We offer guaranteed success in <a
href="http://www.test-king.com/exams/646-671.htm">646-671</a> as well as <a
href="http://www.test-king.com/exams/646-985.htm">646-985</a> exam using world’s best quality <a
href="http://www.test-king.com/exams/E20-340.htm">E20-340</a> training resources.</div><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Fix+Intermittent+MySQL+Errcode+13+Errors+On+Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=How%20To%20Fix%20Intermittent%20MySQL%20Errcode%2013%20Errors%20On%20Windows&amp;link=http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/&amp;notes=%20%0D%0AThe%20Problem%0D%0AI%27ve%20had%20MySQL%20on%20my%20Windows%207%20laptop%20for%20a%20bit%20%28as%20part%20of%20wampserver%29%2C%20mostly%20for%20local%20offline%20Wordpress%20development.%0D%0AHowever%2C%20even%20though%20MySQL%20is%20relatively%20stable%2C%20I%27ve%20been%20observing%20a%20vast%20quantity%20of%20intermittent%20MySQL%20errors%2C%20as%20reported%20by%20Wordpress%20in%20the%20PHP%20error%20log%20%28&amp;short_link=http://bit.ly/cJxOPu&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2010/03/21/how-to-diagnose-and-fix-incorrect-post-comment-counts-in-wordpress/" rel="bookmark" title="March 21, 2010">How To Diagnose And Fix Incorrect Post Comment Counts In WordPress</a></li><li><a
href="http://beerpla.net/2008/04/15/mysql-conference-liveblogging-explain-demystified-tuesday-200p/" rel="bookmark" title="April 15, 2008">MySQL Conference Liveblogging: EXPLAIN Demystified (Tuesday 2:00PM)</a></li><li><a
href="http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/" rel="bookmark" title="February 17, 2009">Swapping Column Values in MySQL</a></li><li><a
href="http://beerpla.net/2009/05/11/mysql-deletingupdating-rows-common-to-2-tables-speed-and-slave-lag-considerations/" rel="bookmark" title="May 11, 2009">[MySQL] Deleting/Updating Rows Common To 2 Tables &#8211; Speed And Slave Lag Considerations</a></li><li><a
href="http://beerpla.net/2008/04/16/mysql-conference-liveblogging-benchmarking-tools-wednesday-425pm/" rel="bookmark" title="April 16, 2008">MySQL Conference Liveblogging: Benchmarking Tools (Wednesday 4:25PM)</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2010%2F01%2F05%2Fhow-to-fix-intermittent-mysql-errcode-13-errors-on-windows%2F&amp;title=How%20To%20Fix%20Intermittent%20MySQL%20Errcode%2013%20Errors%20On%20Windows" id="wpa2a_2"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2010/01/05/how-to-fix-intermittent-mysql-errcode-13-errors-on-windows/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Comparison Between Solr And Sphinx Search Servers (Solr Vs Sphinx &#8211; Fight!)</title><link>http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/</link> <comments>http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/#comments</comments> <pubDate>Thu, 03 Sep 2009 15:00:00 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Solr]]></category> <category><![CDATA[backend]]></category> <category><![CDATA[compare]]></category> <category><![CDATA[comparison]]></category> <category><![CDATA[engine]]></category> <category><![CDATA[enterprise]]></category> <category><![CDATA[fulltext]]></category> <category><![CDATA[indexing]]></category> <category><![CDATA[search]]></category> <category><![CDATA[server]]></category> <category><![CDATA[sphinx]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/09/03/detailed-comparison-between-solr-and-sphinx/</guid> <description><![CDATA[<p>In the past few weeks I&#039;ve been implementing advanced search at <a
rel="nofollow" href="http://www.plaxo.com">Plaxo</a>, working quite closely with <a
rel="nofollow" href="http://lucene.apache.org/solr/">Solr</a> enterprise search server. Today, I saw this relatively detailed comparison between Solr and its main competitor <a
rel="nofollow" href="http://www.sphinxsearch.com/">Sphinx</a> (full credit goes to StackOverflow user <a
rel="nofollow" href="http://stackoverflow.com/users/21239/mausch">mausch</a> who had been using Solr for the past 2 years). For those still confused, Solr and Sphinx are similar to MySQL FULLTEXT search, or for those even more confused, think Google (yeah, this is a bit of a stretch, I know).</p><h2>Similarities</h2><ul><li>Both Solr and Sphinx satisfy all of your requirements. They&#039;re fast and designed to index and search large bodies of data efficiently.</li><li>Both have a long list of</li></ul><p>...<div
class=clear></div> <a
href="http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p>In the past few weeks I&#039;ve been implementing advanced search at <a
rel="nofollow" href="http://www.plaxo.com">Plaxo</a>, working quite closely with <a
rel="nofollow" href="http://lucene.apache.org/solr/">Solr</a> enterprise search server. Today, I saw this relatively detailed comparison between Solr and its main competitor <a
rel="nofollow" href="http://www.sphinxsearch.com/">Sphinx</a> (full credit goes to StackOverflow user <a
rel="nofollow" href="http://stackoverflow.com/users/21239/mausch">mausch</a> who had been using Solr for the past 2 years). For those still confused, Solr and Sphinx are similar to MySQL FULLTEXT search, or for those even more confused, think Google (yeah, this is a bit of a stretch, I know).</p><h2>Similarities</h2><ul><li>Both Solr and Sphinx satisfy all of your requirements. They&#039;re fast and designed to index and search large bodies of data efficiently.</li><li>Both have a long list of high-traffic sites using them (<a
rel="nofollow" href="http://wiki.apache.org/solr/PublicServers">Solr</a>, <a
rel="nofollow" href="http://www.sphinxsearch.com/powered.html">Sphinx</a>)</li><li>Both offer commercial support. (<a
rel="nofollow" href="http://www.lucidimagination.com/">Solr</a>, <a
rel="nofollow" href="http://www.sphinxsearch.com/consulting.html">Sphinx</a>)</li><li>Both offer client API bindings for several platforms/languages (<a
rel="nofollow" href="http://www.sphinxsearch.com/contribs.html">Sphinx</a>, <a
rel="nofollow" href="http://wiki.apache.org/solr/#head-ab1768efa59b26cbd30f1acd03b633f1d110ed47">Solr</a>)</li><li>Both can be distributed to increase speed and capacity (<a
rel="nofollow" href="http://www.sphinxsearch.com/docs/current.html#distributed">Sphinx</a>, <a
rel="nofollow" href="http://wiki.apache.org/solr/DistributedSearch">Solr</a>)</li></ul><h2>Here are some differences</h2><ul><li>Solr, being an Apache project, is obviously is Apache2-licensed. <a
rel="nofollow" href="http://www.sphinxsearch.com/licensing.html">Sphinx is GPLv2</a>. This means that if you ever need to embed or extend (not just &#034;use&#034;) Sphinx in a commercial application, you&#039;ll have to buy a commercial license.</li><li>Solr is <a
rel="nofollow" href="http://wiki.apache.org/solr/Solrj#head-02003c15f194db1a691f8b9bb909145a60ccf498">easily embeddable</a> in Java applications.</li><li>Solr is built on top of Lucene, which is a proven technology over <a
rel="nofollow" href="http://svn.apache.org/viewvc/lucene/java/tags/LUCENE%5F1%5F0%5F1/">7 years old</a> with a <a
rel="nofollow" href="http://wiki.apache.org/lucene-java/PoweredBy">huge user base</a> (this is only a small part). Whenever Lucene gets a new feature or speedup, Solr gets it too. Many of the devs committing to Solr are also Lucene committers.</li><li>Sphinx integrates more tightly with RDBMSs, especially MySQL.</li><li>Solr can be <a
rel="nofollow" href="http://highscalability.com/how-rackspace-now-uses-mapreduce-and-hadoop-query-terabytes-data">integrated with Hadoop to build distributed applications</a></li><li>Solr can be <a
rel="nofollow" href="http://stackoverflow.com/questions/211411/using-nutch-crawler-with-solr">integrated with Nutch to quickly build a fully-fledged web search engine with crawler</a>.</li><li>Solr can <a
rel="nofollow" href="http://wiki.apache.org/solr/ExtractingRequestHandler">index proprietary formats like Microsoft Word, PDF, etc</a>. Sphinx <a
rel="nofollow" href="http://stackoverflow.com/questions/1207995/indexing-word-documents-and-pdfs-with-sphinx">can&#039;t</a>.</li><li>Solr comes with a <a
rel="nofollow" href="http://wiki.apache.org/solr/SpellCheckComponent">spell-checker out of the box</a>.</li><li>Solr comes with <a
rel="nofollow" href="http://wiki.apache.org/solr/SolrFacetingOverview">facet support out of the box</a>. Faceting in Sphinx <a
rel="nofollow" href="http://api-meal.eu/memo/128-faceted-search-with-sphinx-and-php/">takes more work</a>.</li><li><a
rel="nofollow" href="http://stackoverflow.com/questions/737275/pros-cons-of-full-text-search-engine-lucene-sphinx-postgresql-full-text-searc/737931#737931">Sphinx doesn&#039;t allow partial index updates for field data</a>.</li><li>In Sphinx, <a
rel="nofollow" href="http://www.sphinxsearch.com/docs/current.html#data-restrictions">all document ids must be unique unsigned non-zero integer numbers</a>. Solr <a
rel="nofollow" href="http://wiki.apache.org/solr/UniqueKey">doesn&#039;t even require a unique key for many operations</a>, and unique keys can be either integers or strings.</li><li>Solr supports <a
href="http://wiki.apache.org/solr/FieldCollapsing">field collapsing</a> to avoid duplicating similar results. Sphinx doesn&#039;t seem to provide any feature like this.</li></ul><h2>Related questions</h2><ul><li><a
title="http://stackoverflow.com/questions/1284083/choosing-a-stand-alone-full-text-search-server-sphinx-or-solr" rel="nofollow" href="http://stackoverflow.com/questions/1284083/choosing-a-stand-alone-full-text-search-server-sphinx-or-solr">http://stackoverflow.com/questions/1284083/choosing-a-stand-alone-full-text-search-server-sphinx-or-solr</a></li><li><a
rel="nofollow" href="http://stackoverflow.com/questions/1132284/full-text-searching-with-rails">http://stackoverflow.com/questions/1132284/full-text-searching-with-rails</a></li><li><a
rel="nofollow" href="http://stackoverflow.com/questions/737275/pros-cons-of-full-text-search-engine-lucene-sphinx-postgresql-full-text-searc">http://stackoverflow.com/questions/737275/pros-cons-of-full-text-search-engine-lucene-sphinx-postgresql-full-text-searc</a></li></ul><h2>Conclusion</h2><p>In my experience, Solr is very-very fast on the query side. It is also very powerful. The indexing side is very CPU and memory intensive and is an unfortunate side effect of having such a feature-rich, fast application. Nevertheless, I highly recommend Solr.</p><p>For disclaimer purposes, I have not had much experience with Sphinx and, again, all credit for this comparison goes to <a
rel="nofollow" href="http://stackoverflow.com/users/21239/mausch">mausch</a>.</p><p>By the way, here&#039;s a really good resource for Solr 1.4 that just came out: <a
href="http://www.amazon.com/dp/1847195881/?tag=beepla-20">Solr 1.4 Enterprise Search</a>. I have this book and it&#039;s quite helpful in explaining such topics as multicore setup, search methods, replication, etc.</p><p
align="center"><iframe
src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=beepla-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=1847195881" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p><div
class='post_blob_1'>We offer the best quality <a
href="http://www.test-king.com/exams/70-648.htm">70-648</a> resources. Use our latest <a
href="http://www.test-king.com/exams/1Y0-A08.htm">1Y0-A08</a> questions and <a
href="http://www.test-king.com/exams/642-357.htm">642-357</a> answers to pass your certification exams.</div><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison+Between+Solr+And+Sphinx+Search+Servers+%28Solr+Vs+Sphinx+-+Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=Comparison%20Between%20Solr%20And%20Sphinx%20Search%20Servers%20%28Solr%20Vs%20Sphinx%20-%20Fight%21%29&amp;link=http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/&amp;notes=In%20the%20past%20few%20weeks%20I%27ve%20been%20implementing%20advanced%20search%20at%20Plaxo%2C%20working%20quite%20closely%20with%20Solr%20enterprise%20search%20server.%20Today%2C%20I%20saw%20this%20relatively%20detailed%20comparison%20between%20Solr%20and%20its%20main%20competitor%20Sphinx%20%28full%20credit%20goes%20to%20StackOverflow%20user%20mausch%20who%20had%20been%20using%20Solr%20for%20the&amp;short_link=http://bit.ly/9TGaBF&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2009/09/21/solr-how-to-fix-java-io-ioexception-directory-foo-exists-and-is-a-directory-but-cannot-be-listed-list-returned-null/" rel="bookmark" title="September 21, 2009">[Solr] How To Fix java.io.IOException: directory FOO exists and is a directory, but cannot be listed: list() returned null</a></li><li><a
href="http://beerpla.net/2009/08/18/delicious-com-quietly-rolls-out-domain-and-url-searchingfiltering-finally/" rel="bookmark" title="August 18, 2009">Delicious.com [Quietly] Rolls Out Domain And Url Searching/Filtering. Finally!</a></li><li><a
href="http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/" rel="bookmark" title="June 21, 2009">Hidden Features Of Perl, PHP, Javascript, C, C++, C#, Java, Ruby, Python, And Others [Collection Of Incredibly Useful Lists]</a></li><li><a
href="http://beerpla.net/2008/04/13/my-mysql-conference-schedule/" rel="bookmark" title="April 13, 2008">My MySQL Conference Schedule</a></li><li><a
href="http://beerpla.net/2011/06/13/goodbye-outlook-i-dont-need-you-anymore-gmail-now-lets-you-paste-images-directly-from-clipboard/" rel="bookmark" title="June 13, 2011">[Updated x3] Goodbye Outlook, I Don&#039;t Need You Anymore &#8211; Gmail Now Lets You Paste Images Directly From Clipboard</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F09%2F03%2Fcomparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight%2F&amp;title=Comparison%20Between%20Solr%20And%20Sphinx%20Search%20Servers%20%28Solr%20Vs%20Sphinx%20%26%238211%3B%20Fight%21%29" id="wpa2a_4"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Hidden Features Of Perl, PHP, Javascript, C, C++, C#, Java, Ruby, Python, And Others [Collection Of Incredibly Useful Lists]</title><link>http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/</link> <comments>http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/#comments</comments> <pubDate>Sun, 21 Jun 2009 19:38:56 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[C]]></category> <category><![CDATA[C Sharp]]></category> <category><![CDATA[C++]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[Databases]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Perl]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Ruby]]></category> <category><![CDATA[asp.net]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[code]]></category> <category><![CDATA[delphi]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[emacs]]></category> <category><![CDATA[f#]]></category> <category><![CDATA[feature]]></category> <category><![CDATA[featured]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[greasemonkey]]></category> <category><![CDATA[haskell]]></category> <category><![CDATA[hidden]]></category> <category><![CDATA[http]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[language]]></category> <category><![CDATA[lua]]></category> <category><![CDATA[mod_rewrite]]></category> <category><![CDATA[objective-c]]></category> <category><![CDATA[oracle]]></category> <category><![CDATA[program]]></category> <category><![CDATA[regex]]></category> <category><![CDATA[ror]]></category> <category><![CDATA[ruby on rails]]></category> <category><![CDATA[scala]]></category> <category><![CDATA[secret]]></category> <category><![CDATA[spring]]></category> <category><![CDATA[tcl]]></category> <category><![CDATA[vb.net]]></category> <category><![CDATA[xpath]]></category> <category><![CDATA[xslt]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/</guid> <description><![CDATA[<h2 align="left">Introduction</h2><p><a
href="http://www.stackoverflow.com">StackOverflow</a> is an amazing site for coding questions. It was created by <a
href="http://twitter.com/Spolsky" rel="nofollow">Joel Spolsky</a> of <a
href="http://joelonsoftware.com" rel="nofollow">joelonsoftware.com</a>, <a
href="http://twitter.com/codinghorror" rel="nofollow">Jeff Atwood</a> of <a
href="http://codinghorror.com" rel="nofollow">codinghorror.com</a>, and some other incredibly smart guys who truly care about user experience. I have been a total fan of SO since it went mainstream and it&#039;s now a borderline addiction (you can see my StackOverflow badge on the right sidebar).</p><h2 align="left">The Story</h2><p
align="left"><div
class="note"><div
class="noteimportant"></div></div></p><p
align="left"><strong>Update 6/21/09</strong>: This server is currently under very heavy load (10-200), even with caching plugins enabled. Please bear with me as I try to resolve the situation.</p><p
align="left">Feel free to <a
href="http://www.addtoany.com/share_save?&#38;linkurl=http%3A%2F%2Fbeerpla.net%2F2009%2F06%2F21%2Fhidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists%2F&#38;linkname=Hidden%20Features%20Of%20Perl%2C%20PHP%2C%20Javascript%2C%20C%2C%20C%2B%2B%2C%20C%23%2C%20Java%2C%20Ruby%2C%20Python%2C%20And%20Others%20%5BCollection%20Of%20Incredibly%20Useful%20Lists%5D">bookmark this page</a> and return to it later when the fires have...<div
class=clear></div> <a
href="http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<h2 align="left">Introduction</h2><p><a
href="http://www.stackoverflow.com">StackOverflow</a> is an amazing site for coding questions. It was created by <a
href="http://twitter.com/Spolsky" rel="nofollow">Joel Spolsky</a> of <a
href="http://joelonsoftware.com" rel="nofollow">joelonsoftware.com</a>, <a
href="http://twitter.com/codinghorror" rel="nofollow">Jeff Atwood</a> of <a
href="http://codinghorror.com" rel="nofollow">codinghorror.com</a>, and some other incredibly smart guys who truly care about user experience. I have been a total fan of SO since it went mainstream and it&#039;s now a borderline addiction (you can see my StackOverflow badge on the right sidebar).</p><h2 align="left">The Story</h2><p
align="left"><div
class="note"><div
class="noteimportant"></p><p
align="left"><strong>Update 6/21/09</strong>: This server is currently under very heavy load (10-200), even with caching plugins enabled. Please bear with me as I try to resolve the situation.</p><p
align="left">Feel free to <a
href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fbeerpla.net%2F2009%2F06%2F21%2Fhidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists%2F&amp;linkname=Hidden%20Features%20Of%20Perl%2C%20PHP%2C%20Javascript%2C%20C%2C%20C%2B%2B%2C%20C%23%2C%20Java%2C%20Ruby%2C%20Python%2C%20And%20Others%20%5BCollection%20Of%20Incredibly%20Useful%20Lists%5D">bookmark this page</a> and return to it later when the fires have been put out.</p><p
align="left"><strong>Update 06/21/09</strong>: I think I&#039;ve got the situation under control now. The load is between 0 and 3 now and pages load relatively fast. I will be posting about the getting redditted/delicioused experience later.</p><p
align="left"><strong>Update 06/23/09</strong>: Added jQuery, Greasemonkey, Ruby on Rails, and Objective-C, broke databases into their own section, and sorted everything alphabetically.</p><p
align="left"><strong>Update 06/23/09</strong>: Added Scala, Lua, TCL, F#, Regex, and HTTP.</p><p
align="left"><strong>Update 07/21/09</strong>: Added ActionScript3/Flex, Erlang, PL/SQL, Silverlight, VBA, VHDL, WPF/XAML.</p><p
align="left"><strong>Update 10/24/09</strong>: Added Flash development/language/IDE, Emacs, Xpath/Xslt, Spring framework.</p><p
align="left"><strong>Update 01/18/10</strong>: Added Android (asked by yours truly), Qt, Django, Windows.Forms, R, Lisp, x86 assembly, Grails.</p><p
align="left"></div></div></p><p>So, one day someone at StackOverflow started a &quot;Hidden features of&quot; post about a famous language (I don&#039;t feel like finding out which one was first exactly), and it turned out to be so popular that other posts in the same series started popping up.</p><p>Such questions were quickly turned into community wikis, for the purposes of harvesting and organizing information coming from the best developers on the planet and voted by users of the site. There are literally hundreds of answers, sorted by votes.</p><p><div
class="note"><div
class="notetip">The Hidden Features series is great for people who are new to a certain language. It shows the ropes and tricks, all in one place, in the most concise manner possible. Even pros oftentimes find features of their favorite language that they&#039;d never heard about.</div></div></p><h2 align="center">Hidden Features Of</h2><h3>Programming Languages</h3><h4><a
href="http://stackoverflow.com/questions/1103705/hidden-features-of-actionscript3-flex">Hidden features of ActionScript3 / Flex</a></h4><h4><a
href="http://stackoverflow.com/questions/54929/hidden-features-of-asp-net">Hidden features of ASP.NET </a></h4><h4><a
href="http://stackoverflow.com/questions/1574308/hidden-features-of-x86-assembly-language" rel="nofollow">Hidden features of x86 assembly</a></h4><h4><a
href="http://stackoverflow.com/questions/132241/hidden-features-of-c">Hidden features of C</a></h4><h4><a
href="http://stackoverflow.com/questions/75538/hidden-features-of-c">Hidden features of C++</a></h4><h4><a
href="http://stackoverflow.com/questions/9033/hidden-features-of-c">Hidden features of C#</a></h4><h4><a
href="http://stackoverflow.com/questions/1853653/hidden-features-of-coldfusion" rel="nofollow">Hidden features of ColdFusion</a></h4><h4><a
href="http://stackoverflow.com/questions/125008/hidden-features-of-d">Hidden features of D </a></h4><h4><a
href="http://stackoverflow.com/questions/102254/hidden-features-of-delphi" rel="nofollow">Hidden features of Delphi</a></h4><h4><a
href="http://stackoverflow.com/questions/1063497/hidden-features-of-erlang" rel="nofollow">Hidden features of Erlang</a></h4><h4><a
href="http://stackoverflow.com/questions/181613/hidden-features-of-f">Hidden features of F# </a></h4><h4><a
href="http://stackoverflow.com/questions/1160680/hidden-features-tricks-of-flash-development-flash-language-as2-3-and-flash-id" rel="nofollow">Hidden features of Flash development, Flash language (AS2/3), and Flash IDE</a></h4><h4><a
href="http://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden features of Java</a></h4><h4><a
href="http://stackoverflow.com/questions/61088/hidden-features-of-javascript">Hidden features of JavaScript</a></h4><h4><a
href="http://stackoverflow.com/questions/211216/hidden-features-of-haskell">Hidden features of Haskell </a></h4><h4><a
href="http://stackoverflow.com/questions/1598854/hidden-features-of-emacs-lisp" rel="nofollow">Hidden features of Lisp</a></h4><h4><a
href="http://stackoverflow.com/questions/523867/hidden-features-of-lua">Hidden features of Lua </a></h4><h4><a
href="http://stackoverflow.com/questions/211616/hidden-features-of-objective-c">Hidden features of Objective-C </a></h4><h4><a
href="http://stackoverflow.com/questions/161872/hidden-features-of-perl">Hidden features of Perl</a></h4><h4><a
href="http://stackoverflow.com/questions/61401/hidden-features-of-php">Hidden features of PHP</a></h4><h4><a
href="http://stackoverflow.com/questions/101268/hidden-features-of-python">Hidden features of Python</a></h4><h4><a
href="http://stackoverflow.com/questions/1682874/hidden-features-of-r" rel="nofollow">Hidden features of R</a></h4><h4><a
href="http://stackoverflow.com/questions/63998/hidden-features-of-ruby">Hidden features of Ruby</a></h4><h4><a
href="http://stackoverflow.com/questions/709679/hidden-features-of-ruby-on-rails">Hidden features of Ruby on Rails </a></h4><h4><a
href="http://stackoverflow.com/questions/1025181/hidden-features-of-scala">Hidden features of Scala </a></h4><h4><a
href="http://stackoverflow.com/questions/1031450/are-there-any-undocumented-features-in-silverlight">Hidden features of Silverlight</a></h4><h4><a
href="http://stackoverflow.com/questions/1596139/hidden-features-and-dark-corners-of-stl" rel="nofollow">Hidden features and Dark Corners of STL?</a></h4><h4><a
href="http://stackoverflow.com/questions/1024711/hidden-features-of-tcl-tk">Hidden features of TCL/TK</a></h4><h4><a
href="http://stackoverflow.com/questions/102084/hidden-features-of-vb-net">Hidden features of VB.Net </a></h4><h4><a
href="http://stackoverflow.com/questions/1070863/hidden-features-of-vba">Hidden features of VBA</a></h4><h3>Databases</h3><h4><a
href="http://stackoverflow.com/questions/368858/hidden-features-of-mysql">Hidden features of MySQL </a></h4><h4><a
href="http://stackoverflow.com/questions/381231/hidden-features-in-oracle">Hidden features of Oracle </a></h4><h4><a
href="http://stackoverflow.com/questions/1031485/hidden-features-of-pl-sql">Hidden features of PL/SQL</a></h4><h4><a
href="http://stackoverflow.com/questions/761327/hidden-features-of-postgresql">Hidden features of PostgreSQL </a></h4><h4><a
href="http://stackoverflow.com/questions/121243/hidden-features-of-sql-server">Hidden features of SQL Server </a></h4><h3>Mobile</h3><h4><a
href="http://stackoverflow.com/questions/1619133/hidden-features-of-android-development" rel="nofollow">Hidden features of Android development</a></h4><h3>Other</h3><h4><a
href="http://stackoverflow.com/questions/211378/hidden-features-of-bash">Hidden features of Bash</a> &#8211; also see my <a
href="http://beerpla.net/2008/12/22/mastering-the-linux-shell-bash-shortcuts-explained/">bash cheatsheet</a>.</h4><h4><a
href="http://stackoverflow.com/questions/628407/css-hidden-features">Hidden features of CSS</a></h4><h4><a
href="http://stackoverflow.com/questions/1858520/hidden-features-of-django" rel="nofollow">Hidden features of Django</a></h4><h4><a
href="http://stackoverflow.com/questions/54886/hidden-features-tricks-for-eclipse">Hidden features of Eclipse </a></h4><h4><a
href="http://stackoverflow.com/questions/1598854/hidden-features-of-emacs-lisp" rel="nofollow">Hidden features of Emacs</a></h4><h4><a
href="http://stackoverflow.com/questions/1330531/hidden-features-of-grails" rel="nofollow">Hidden features of Grails</a></h4><h4><a
href="http://stackoverflow.com/questions/121167/hidden-features-of-greasemonkey">Hidden features of Greasemonkey </a></h4><h4><a
href="http://stackoverflow.com/questions/954327/hidden-features-of-html">Hidden features of HTML </a></h4><h4><a
href="http://stackoverflow.com/questions/954894/hidden-features-of-http">Hidden features of HTTP </a></h4><h4><a
href="http://stackoverflow.com/questions/121965/hidden-or-not-widely-known-features-of-jquery">Hidden features of jQuery</a></h4><h4><a
href="http://stackoverflow.com/questions/286004/hidden-features-of-modrewrite">Hidden features of mod_rewrite </a></h4><h4><a
href="http://stackoverflow.com/questions/1826458/hidden-features-of-qt" rel="nofollow">Hidden features of Qt</a></h4><h4><a
href="http://stackoverflow.com/questions/868181/hidden-features-of-regex">Hidden features of RegEx </a></h4><h4><a
href="http://stackoverflow.com/questions/1416423/hidden-features-of-spring-framework">Hidden features of Spring framework </a></h4><h4><a
href="http://stackoverflow.com/questions/1025699/hidden-features-of-vhdl">Hidden features of VHDL</a></h4><h4><a
href="http://stackoverflow.com/questions/100420/hidden-features-of-visual-studio-2005-2008">Hidden features of Visual Studio (2005-2008) </a></h4><h4><a
href="http://stackoverflow.com/questions/1777303/hidden-features-of-windows-forms" rel="nofollow">Hidden features of Windows.Forms</a></h4><h4><a
href="http://stackoverflow.com/questions/1124769/hidden-features-of-wpf-and-xaml">Hidden features of WPF and XAML</a></h4><h4><a
href="http://stackoverflow.com/questions/1521851/hidden-features-of-xpathxslt">Hidden features of Xpath+Xslt</a></h4><p>I will try to maintain this list, adding new languages that join the series as I find them. Now go learn something new!</p><div
class='post_blob_1'>Real <a
href="http://www.test-king.com/exams/70-432.htm">70-432</a> exam preparation with help of easy to understand <a
href="http://www.test-king.com/exams/220-702.htm">220-702</a> notes and <a
href="http://www.test-king.com/exams/640-553.htm">640-553</a> practice questions.</div><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden+Features+Of+Perl%2C+PHP%2C+Javascript%2C+C%2C+C%2B%2B%2C+C%23%2C+Java%2C+Ruby%2C+Python%2C+And+Others+%5BCollection+Of+Incredibly+Useful+Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=Hidden%20Features%20Of%20Perl%2C%20PHP%2C%20Javascript%2C%20C%2C%20C%2B%2B%2C%20C%23%2C%20Java%2C%20Ruby%2C%20Python%2C%20And%20Others%20%5BCollection%20Of%20Incredibly%20Useful%20Lists%5D&amp;link=http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/&amp;notes=Introduction%0D%0AStackOverflow%20is%20an%20amazing%20site%20for%20coding%20questions.%20It%20was%20created%20by%20Joel%20Spolsky%20of%20joelonsoftware.com%2C%20Jeff%20Atwood%20of%20codinghorror.com%2C%20and%20some%20other%20incredibly%20smart%20guys%20who%20truly%20care%20about%20user%20experience.%20I%20have%20been%20a%20total%20fan%20of%20SO%20since%20it%20went%20mainstream%20and%20it%27s%20now%20a&amp;short_link=http://bit.ly/capw5J&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2009/10/24/are-you-a-stackoverflow-com-superuser-com-serverfault-com-fan-heres-a-greasemonkey-script-to-keep-track-of-your-accounts-on-all-of-them/" rel="bookmark" title="October 24, 2009">StackOverflow.com, SuperUser.com, ServerFault.com Fan? Here&#039;s A Greasemonkey Script To Keep Track Of All Your Accounts</a></li><li><a
href="http://beerpla.net/2009/09/03/comparison-between-solr-and-sphinx-search-servers-solr-vs-sphinx-fight/" rel="bookmark" title="September 3, 2009">Comparison Between Solr And Sphinx Search Servers (Solr Vs Sphinx &#8211; Fight!)</a></li><li><a
href="http://beerpla.net/2009/03/17/twitter-autocomplete-auto-url-expansion-auto-url-shortener-auto-pagination-rt-button-nested-replies-inline-media-embed-search-tabs-and-more/" rel="bookmark" title="March 17, 2009">Twitter.com Autocomplete, Auto URL Expansion, Auto URL Shortener, RT Button, Nested Replies, Inline Media Embed, Search Tabs, And More</a></li><li><a
href="http://beerpla.net/2010/01/18/wordpress-developers-how-do-you-make-a-living-poll-discussion/" rel="bookmark" title="January 18, 2010">WordPress Developers &#8211; How Do You Make A Living [Poll + Discussion]?</a></li><li><a
href="http://beerpla.net/2009/08/18/delicious-com-quietly-rolls-out-domain-and-url-searchingfiltering-finally/" rel="bookmark" title="August 18, 2009">Delicious.com [Quietly] Rolls Out Domain And Url Searching/Filtering. Finally!</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F06%2F21%2Fhidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists%2F&amp;title=Hidden%20Features%20Of%20Perl%2C%20PHP%2C%20Javascript%2C%20C%2C%20C%2B%2B%2C%20C%23%2C%20Java%2C%20Ruby%2C%20Python%2C%20And%20Others%20%5BCollection%20Of%20Incredibly%20Useful%20Lists%5D" id="wpa2a_6"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/feed/</wfw:commentRss> <slash:comments>23</slash:comments> </item> <item><title>MySQL Indexing Considerations Of Implementing A Priority Field In Your Application</title><link>http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/</link> <comments>http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/#comments</comments> <pubDate>Wed, 18 Mar 2009 14:00:00 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[asc]]></category> <category><![CDATA[desc]]></category> <category><![CDATA[how]]></category> <category><![CDATA[index]]></category> <category><![CDATA[order]]></category> <category><![CDATA[priority]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[solution]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/</guid> <description><![CDATA[<h2>Introduction</h2><p>If you, like me, are building or thinking of implementing a MySQL-powered application that has any need for prioritizing selecting certain data over other data, this article is for you.</p><h2>Example</h2><p>As a real world example, consider a queue-like video processing system. Your application receives new videos and processes them. The volume of incoming videos can at times be higher than the processing rate because the process is CPU bound, so occasionally a pretty long queue may form. You will try to process them as fast as you can but…</p><p><div
class="note"><div
class="noteclassic">Note that I am using a queue here, so the <strong>the next item to be processed is a result of sorting by some sort of field in a <em>ascending</em></strong></div></div>...<div
class=clear></div> <a
href="http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<h2>Introduction</h2><p>If you, like me, are building or thinking of implementing a MySQL-powered application that has any need for prioritizing selecting certain data over other data, this article is for you.</p><h2>Example</h2><p>As a real world example, consider a queue-like video processing system. Your application receives new videos and processes them. The volume of incoming videos can at times be higher than the processing rate because the process is CPU bound, so occasionally a pretty long queue may form. You will try to process them as fast as you can but…</p><p><div
class="note"><div
class="noteclassic">Note that I am using a queue here, so the <strong>the next item to be processed is a result of sorting by some sort of field in a <em>ascending </em>order</strong>, for example ORDER BY id or ORDER BY upload_date. I’ll pick the id sort here.</div></div></p><p>…suddenly, you need to process a video somewhere in the middle of the queue or an important video enters and needs immediate attention. What do you do?</p><p>An obvious solution is implementing a simple priority system where each item has a numeric priority field. Now you can sort first by priority from highest to lowest and then by id within the highest priority. Important and urgent items get a their priority changed to something higher and get processed first. There is only one problem.</p><h2>Problem</h2><p>The problem is pretty serious – let’s take a look at the SELECT statement. Before selecting, I’ve added 19 random rows to have some data to work on.</p><div
class="wp_syntax"><div
class="code"><pre>SELECT * FROM queue ORDER BY priority DESC, id LIMIT 1;</pre></div></div><p>What kind of index would you put on this table to speed up this query? You do want to add a proper index, don’t you? DO YOU? Ok, good.</p><p>&nbsp;</p><p>Here’s what happens without any indexes:</p><div
class="wp_syntax"><div
class="code"><pre>mysql&gt; EXPLAIN SELECT * FROM queue ORDER BY priority DESC, id LIMIT 1;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
|  1 | SIMPLE      | queue | ALL  | NULL          | NULL | NULL    | NULL |   19 | Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)</pre></div></div><p><em>Using filesort</em>, ugh, of course, due to sorting without an index.</p><p>&nbsp;</p><p>Let’s see, how about a combined index on (priority, id)?</p><div
class="wp_syntax"><div
class="code"><pre>mysql&gt; ALTER TABLE `queue` ADD INDEX `priority_id`(`priority`, `id`);
Query OK, 19 rows affected (0.05 sec)
Records: 19  Duplicates: 0  Warnings: 0
&nbsp;
mysql&gt; EXPLAIN SELECT * FROM queue ORDER BY priority DESC, id LIMIT 1;
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
| id | select_type | table | type  | possible_keys | key         | key_len | ref  | rows | Extra                       |
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
|  1 | SIMPLE      | queue | index | NULL          | priority_id | 5       | NULL |   19 | Using index; Using filesort |
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
1 row in set (0.00 sec)</pre></div></div><p>Better because an index is being used but not very good because filesort is still present. “Of course!”, you slap yourself on the forehead. The first ORDER BY uses a DESCENDING order, and our key is in ASCENDING order.</p><p>&nbsp;</p><p>So, let’s add the proper key with the right ordering instead.</p><div
class="wp_syntax"><div
class="code"><pre>mysql&gt; ALTER TABLE `queue` DROP INDEX `priority_id`;
Query OK, 19 rows affected (0.05 sec)
Records: 19  Duplicates: 0  Warnings: 0
&nbsp;
mysql&gt; ALTER TABLE `queue` ADD INDEX `priority_id`(`priority` DESC, `id`);
Query OK, 19 rows affected (0.06 sec)
Records: 19  Duplicates: 0  Warnings: 0</pre></div></div><div
class="wp_syntax"><div
class="code"><pre>mysql&gt; EXPLAIN SELECT * FROM queue ORDER BY priority DESC, id LIMIT 1;
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
| id | select_type | table | type  | possible_keys | key         | key_len | ref  | rows | Extra                       |
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
|  1 | SIMPLE      | queue | index | NULL          | priority_id | 5       | NULL |   19 | Using index; Using filesort |
+----+-------------+-------+-------+---------------+-------------+---------+------+------+-----------------------------+
1 row in set (0.00 sec)</pre></div></div><pre></pre><p>What the deuce? This is the same result as with the previous index. Time to dig up the documentation.</p><p>&nbsp;</p><p>Here is what the MySQL manual has to say under the <a
href="http://dev.mysql.com/doc/refman/5.1/en/order-by-optimization.html">ORDER BY optimization</a> section:</p><blockquote><p>MySQL <em>cannot</em> use indexes to resolve the ORDER BY, although it still uses indexes to find the rows that match the WHERE clause … if you mix ASC and DESC:</p></blockquote><blockquote><div
class="wp_syntax"><div
class="code"><pre>SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;</pre></div></div></blockquote><p>Moreover, to confuse the user even more, the index creation command accepts the DESC instruction, without actually honoring it, as specified in the <a
href="http://dev.mysql.com/doc/refman/5.1/en/create-index.html" rel="nofollow">CREATE INDEX</a> section:</p><blockquote><p>An <em>index_col_name</em> specification can end with ASC or DESC. These keywords are allowed for future extensions for specifying ascending or descending index value storage. Currently, they are parsed but ignored; index values are always stored in ascending order.</p></blockquote><p>So, after so many years MySQL still doesn’t support such basic functionality – you are either stuck with a query that uses filesort or have to look for a workaround.</p><h2>Solution</h2><p>Since it’s not possible to mix order directions, the solution is then to change the meaning of the priority column to match your needs. Thus, in the new approach priority 1 is higher than priority 10, and the application logic needs to accommodate to that. If you caught this while the application is still young, the code may be easy to change, but otherwise it could be a major pain in the butt.</p><h2>Conclusion</h2><p>The moral here is: plan your queries ahead and don’t mix and match DESC and ASC ordering as MySQL will not be able to use an index to resolve it. Do it even sooner if you’re putting lots and lots of data into your tables.</p><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL+Indexing+Considerations+Of+Implementing+A+Priority+Field+In+Your+Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=MySQL%20Indexing%20Considerations%20Of%20Implementing%20A%20Priority%20Field%20In%20Your%20Application&amp;link=http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/&amp;notes=Introduction%20If%20you%2C%20like%20me%2C%20are%20building%20or%20thinking%20of%20implementing%20a%20MySQL-powered%20application%20that%20has%20any%20need%20for%20prioritizing%20selecting%20certain%20data%20over%20other%20data%2C%20this%20article%20is%20for%20you.%20Example%20As%20a%20real%20world%20example%2C%20consider%20a%20queue-like%20video%20processing%20system.%20Your%20application%20rece&amp;short_link=http://bit.ly/csuKMb&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2008/04/15/mysql-conference-liveblogging-explain-demystified-tuesday-200p/" rel="bookmark" title="April 15, 2008">MySQL Conference Liveblogging: EXPLAIN Demystified (Tuesday 2:00PM)</a></li><li><a
href="http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/" rel="bookmark" title="February 17, 2009">Swapping Column Values in MySQL</a></li><li><a
href="http://beerpla.net/2009/05/11/mysql-deletingupdating-rows-common-to-2-tables-speed-and-slave-lag-considerations/" rel="bookmark" title="May 11, 2009">[MySQL] Deleting/Updating Rows Common To 2 Tables &#8211; Speed And Slave Lag Considerations</a></li><li><a
href="http://beerpla.net/2008/04/16/mysql-conference-liveblogging-mysql-performance-under-a-microscope-the-tobias-and-jay-show-wednesday-200pm/" rel="bookmark" title="April 16, 2008">MySQL Conference Liveblogging: MySQL Performance Under A Microscope: The Tobias And Jay Show (Wednesday 2:00PM)</a></li><li><a
href="http://beerpla.net/2008/04/17/mysql-conference-liveblogging-optimizing-mysql-for-high-volume-data-logging-applications-thursday-250pm/" rel="bookmark" title="April 17, 2008">MySQL Conference Liveblogging: Optimizing MySQL For High Volume Data Logging Applications (Thursday 2:50PM)</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F03%2F18%2Fmysql-indexing-considerations-of-implementing-a-priority-field-in-your-application%2F&amp;title=MySQL%20Indexing%20Considerations%20Of%20Implementing%20A%20Priority%20Field%20In%20Your%20Application" id="wpa2a_8"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Swapping Column Values in MySQL</title><link>http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/</link> <comments>http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/#comments</comments> <pubDate>Wed, 18 Feb 2009 00:53:47 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[column]]></category> <category><![CDATA[database]]></category> <category><![CDATA[swap]]></category> <category><![CDATA[value]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/</guid> <description><![CDATA[<p>Today I had to swap 2 columns in one of my MySQL tables. The task, which seems easily accomplishable by a temp variable, proved to be a bit harder to complete. But only just a bit.</p><p>Here are my findings:</p><ol><li><p>The</p><div
class="wp_syntax"><div
class="code"><pre>UPDATE swap_test SET x=y, y=x;</pre></div></div><p>approach doesn&#039;t work, as it&#039;ll just set both values to y.</p><p><div
class="note"><div
class="notetip">PostgreSQL seems to handle this query differently, as it apparently uses the old values throughout the whole query. [<a
href="http://www.postgresql.org/docs/8.3/static/sql-update.html">Reference</a>]</div></div></p></li><li><p>Here&#039;s a method that uses a temporary variable. Thanks to Antony from the comments for the &#34;IS NOT NULL&#34; tweak. Without it, the query works unpredictably. See the table schema at the end of the post. This method</p></li></ol><p>...<div
class=clear></div> <a
href="http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p>Today I had to swap 2 columns in one of my MySQL tables. The task, which seems easily accomplishable by a temp variable, proved to be a bit harder to complete. But only just a bit.</p><p>Here are my findings:</p><ol><li><p>The</p><div
class="wp_syntax"><div
class="code"><pre>UPDATE swap_test SET x=y, y=x;</pre></div></div><p>approach doesn&#039;t work, as it&#039;ll just set both values to y.</p><p><div
class="note"><div
class="notetip">PostgreSQL seems to handle this query differently, as it apparently uses the old values throughout the whole query. [<a
href="http://www.postgresql.org/docs/8.3/static/sql-update.html">Reference</a>]</div></div></p></li><li><p>Here&#039;s a method that uses a temporary variable. Thanks to Antony from the comments for the &quot;IS NOT NULL&quot; tweak. Without it, the query works unpredictably. See the table schema at the end of the post. This method doesn&#039;t swap the values if one of them is NULL. Use method #3 that doesn&#039;t have this limitation.</p><div
class="wp_syntax"><div
class="code"><pre>UPDATE swap_test SET x=y, y=@temp WHERE (@temp:=x) IS NOT NULL;</pre></div></div><p><div
class="note"><div
class="notewarning">The parentheses around @temp:=x are critical. Omitting them will cause data corruption.</div></div></p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre>mysql&amp;gt; UPDATE swap_test SET x=y, y=@temp WHERE (@temp:=x) IS NOT NULL;
Query OK, 3 rows affected
Rows matched: 3  Changed: 3  Warnings: 0</pre></td></tr></table></div></li><li><p>This method was offered by Dipin in the comments. I think it’s the most elegant and clean solution. It works with both NULL and non-NULL values.</p><div
class="wp_syntax"><div
class="code"><pre>UPDATE swap_test SET x=(@temp:=x), x = y, y = @temp;</pre></div></div></li><li><p>Another approach I came up with that seems to work:</p><div
class="wp_syntax"><div
class="code"><pre>UPDATE swaptest s1, swaptest s2 SET s1.x=s1.y, s1.y=s2.x WHERE s1.id=s2.id;</pre></div></div><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre>mysql&amp;gt; update swap_test s1, swap_test s2 set s1.x=s1.y, s1.y=s2.x where s1.id=s2.id;
Query OK, 3 rows affected
Rows matched: 3  Changed: 3  Warnings: 0</pre></td></tr></table></div></li></ol><p>Essentially, the 1st table is the one getting updated and the 2nd one is used to pull the old data from.<div
class="note"><div
class="noteclassic">Note that this approach requires a primary key to be present.</div></div></p><p>Test schema used:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td
class="code"><pre>CREATE TABLE `swap_test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `x` varchar(255) DEFAULT NULL,
  `y` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
&nbsp;
INSERT INTO `swap_test` VALUES ('1', 'a', '10');
INSERT INTO `swap_test` VALUES ('2', NULL, '20');
INSERT INTO `swap_test` VALUES ('3', 'c', NULL);</pre></td></tr></table></div><p>Do you have a better approach? If so, please share in the comments.</p><p>Some references:</p><ul><li><a
title="http://stackoverflow.com/questions/37649/swapping-column-values-in-mysql/" href="http://stackoverflow.com/questions/37649/swapping-column-values-in-mysql/">http://stackoverflow.com/questions/37649/swapping-column-values-in-mysql/</a> – some discussion on various methods, which eventually prompted me to start this post</li><li><a
title="http://www.marcworrell.com/article-3026-en.html" href="http://www.marcworrell.com/article-3026-en.html">http://www.marcworrell.com/article-3026-en.html</a> – discussion on the 2nd approach, which doesn’t work</li></ul><div
class='post_blob_1'>Pass your <a
href="http://www.test-king.com/exams/642-524.htm">642-524</a> exam with highest score using latest <a
href="http://www.test-king.com/exams/642-373.htm">642-373</a> practice questions and <a
href="http://www.test-king.com/exams/642-446.htm">642-446</a> sample exams.</div><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping+Column+Values+in+MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=Swapping%20Column%20Values%20in%20MySQL&amp;link=http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/&amp;notes=Today%20I%20had%20to%20swap%202%20columns%20in%20one%20of%20my%20MySQL%20tables.%20The%20task%2C%20which%20seems%20easily%20accomplishable%20by%20a%20temp%20variable%2C%20proved%20to%20be%20a%20bit%20harder%20to%20complete.%20But%20only%20just%20a%20bit.%0D%0AHere%20are%20my%20findings%3A%0D%0A%0D%0A%0D%0AThe%0D%0AUPDATE%20swap_test%20SET%20x%3Dy%2C%20y%3Dx%3Bapproach%20doesn%27t%20work%2C%20as%20it%27ll%20just%20set%20both%20values%20to%20&amp;short_link=http://bit.ly/9F5oZC&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2009/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/" rel="bookmark" title="March 18, 2009">MySQL Indexing Considerations Of Implementing A Priority Field In Your Application</a></li><li><a
href="http://beerpla.net/2008/04/17/mysql-conference-liveblogging-optimizing-mysql-for-high-volume-data-logging-applications-thursday-250pm/" rel="bookmark" title="April 17, 2008">MySQL Conference Liveblogging: Optimizing MySQL For High Volume Data Logging Applications (Thursday 2:50PM)</a></li><li><a
href="http://beerpla.net/2008/04/15/mysql-conference-liveblogging-explain-demystified-tuesday-200p/" rel="bookmark" title="April 15, 2008">MySQL Conference Liveblogging: EXPLAIN Demystified (Tuesday 2:00PM)</a></li><li><a
href="http://beerpla.net/2010/03/21/how-to-diagnose-and-fix-incorrect-post-comment-counts-in-wordpress/" rel="bookmark" title="March 21, 2010">How To Diagnose And Fix Incorrect Post Comment Counts In WordPress</a></li><li><a
href="http://beerpla.net/2009/05/11/mysql-deletingupdating-rows-common-to-2-tables-speed-and-slave-lag-considerations/" rel="bookmark" title="May 11, 2009">[MySQL] Deleting/Updating Rows Common To 2 Tables &#8211; Speed And Slave Lag Considerations</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F02%2F17%2Fswapping-column-values-in-mysql%2F&amp;title=Swapping%20Column%20Values%20in%20MySQL" id="wpa2a_10"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/feed/</wfw:commentRss> <slash:comments>31</slash:comments> </item> </channel> </rss>
