<?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; how</title> <atom:link href="http://beerpla.net/tag/how/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 Properly Set SVN svn:externals Property In SVN Command Line</title><link>http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/</link> <comments>http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/#comments</comments> <pubDate>Sun, 21 Jun 2009 02:01:26 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[SVN]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[error]]></category> <category><![CDATA[external]]></category> <category><![CDATA[externals]]></category> <category><![CDATA[how]]></category> <category><![CDATA[propget]]></category> <category><![CDATA[propset]]></category> <category><![CDATA[set]]></category> <category><![CDATA[svn:externals]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/</guid> <description><![CDATA[<h2>Introduction</h2><p>Every time I have to deal with <a
href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow">svn:externals</a> in SVN, I forget the command line syntax. Every single damn time. Normally, I use SVN GUI clients, such as <a
href="http://www.smartsvn.com/" rel="nofollow">SmartSVN</a>, which make it very simple to add an svn:externals property. But for command line, it always takes looking at 25 different sites on google, which are all incredibly unhelpful for this question for some reason. Trying &#34;svn help propset&#34; on the command line was bloated and equally useless.</p><p>So this time I needed to write it down and make sure everyone who needed help with svn:externals would find exactly what they need here. I hope this page will soon come up on top of all the...<div
class=clear></div> <a
href="http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/" 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>Every time I have to deal with <a
href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow">svn:externals</a> in SVN, I forget the command line syntax. Every single damn time. Normally, I use SVN GUI clients, such as <a
href="http://www.smartsvn.com/" rel="nofollow">SmartSVN</a>, which make it very simple to add an svn:externals property. But for command line, it always takes looking at 25 different sites on google, which are all incredibly unhelpful for this question for some reason. Trying &quot;svn help propset&quot; on the command line was bloated and equally useless.</p><p>So this time I needed to write it down and make sure everyone who needed help with svn:externals would find exactly what they need here. I hope this page will soon come up on top of all the unhelpful results on google for &quot;propset svn:externals&quot; and other related queries.</p><h2>The Problem</h2><p>I want to set a simple svn:externals property in one of my project&#039;s directories, lets say &#039;plugins&#039; (talking about WordPress here). The outcome would be a directory called &#039;akismet&#039; within &#039;plugins&#039; that points to a remote svn url.</p><p>Various combinations of trying to do it produced pathetic results, like</p><div
class="wp_syntax"><div
class="code"><pre>svn propset svn:externals akismet http://plugins.svn.wordpress.org/akismet/trunk
svn: Setting property on non-local target 'http://plugins.svn.wordpress.org/akismet/trunk' needs a base revision</pre></div></div><div
class="wp_syntax"><div
class="code"><pre>svn propset svn:externals . akismet http://plugins.svn.wordpress.org/akismet/trunk
svn: Error parsing svn:externals property on 'akismet': '.'</pre></div></div><div
class="wp_syntax"><div
class="code"><pre>svn propset svn:externals akismet http://plugins.svn.wordpress.org/akismet/trunk akismet
svn: Setting property on non-local target 'http://plugins.svn.wordpress.org/akismet/trunk' needs a base revision</pre></div></div><h2>The Solution</h2><p>Finally, thanks to <a
href="http://www.nabble.com/svn:externals-example-td16552909.html" rel="nofollow">this post</a>, I found the right command:</p><div
class="wp_syntax"><div
class="code"><pre>svn propset svn:externals 'akismet http://plugins.svn.wordpress.org/akismet/trunk' .
property 'svn:externals' set on '.'</pre></div></div><p>Note that dot at the end of the command and the quotes around the directory name and url.</p><p>Now commit via</p><div
class="wp_syntax"><div
class="code"><pre>svn commit</pre></div></div><p>and then</p><div
class="wp_syntax"><div
class="code"><pre>svn up
Fetching external item into 'akismet'
A    akismet/akismet.gif
A    akismet/akismet.php
A    akismet/readme.txt
Updated external to revision 127962.
&nbsp;
Updated to revision 16.</pre></div></div><p>There, was it that hard, forum gurus and blog fiends?</p><p><strong>Edit</strong>: in order to set multiple directory/url pairs in a single svn:externals property, you should put the individual dir/url pairs into a file (let&#039;s call it &#039;svn.externals&#039;), like so</p><div
class="wp_syntax"><div
class="code"><pre>akismet http://svn.wp-plugins.org/akismet/trunk
all-in-one-seo-pack http://svn.wp-plugins.org/all-in-one-seo-pack/trunk</pre></div></div><p>and then apply the property using</p><div
class="wp_syntax"><div
class="code"><pre>svn propset svn:externals -F svn.externals .</pre></div></div><p>You should also just check in &#039;svn.externals&#039; to easily keep track of it.</p><p.One thing I haven't figured out yet is how to perform the same multi-operation without using a file. How does one do it on a single command line?</p><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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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+Properly+Set+SVN+svn%3Aexternals+Property+In+SVN+Command+Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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%20Properly%20Set%20SVN%20svn%3Aexternals%20Property%20In%20SVN%20Command%20Line&amp;link=http://beerpla.net/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/&amp;notes=Introduction%0D%0AEvery%20time%20I%20have%20to%20deal%20with%20svn%3Aexternals%20in%20SVN%2C%20I%20forget%20the%20command%20line%20syntax.%20Every%20single%20damn%20time.%20Normally%2C%20I%20use%20SVN%20GUI%20clients%2C%20such%20as%20SmartSVN%2C%20which%20make%20it%20very%20simple%20to%20add%20an%20svn%3Aexternals%20property.%20But%20for%20command%20line%2C%20it%20always%20takes%20looking%20at%2025%20different%20si&amp;short_link=http://bit.ly/bpA8jU&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/02/20/how-to-view-a-specific-svn-revision-in-your-browser/" rel="bookmark" title="February 20, 2010">How To View A Specific SVN Revision In Your Browser</a></li><li><a
href="http://beerpla.net/2008/06/16/how-to-svn-update-all-your-wordpress-plugins-in-one-go/" rel="bookmark" title="June 16, 2008">How To SVN Update All Your WordPress Plugins In One Go</a></li><li><a
href="http://beerpla.net/2011/11/16/how-to-disableblock-external-http-requests-in-wordpress/" rel="bookmark" title="November 16, 2011">How To: Disable/Block External HTTP Requests In WordPress</a></li><li><a
href="http://beerpla.net/2008/03/29/beer-planet-upgraded-to-wordpress-25/" rel="bookmark" title="March 29, 2008">Beer Planet Upgraded To WordPress 2.5</a></li><li><a
href="http://beerpla.net/2010/03/06/how-to-show-hiddeninvisible-files-in-total-commander-both-locally-and-on-an-ftp-server/" rel="bookmark" title="March 6, 2010">How To Show Hidden/Invisible Files In Total Commander, Both Locally And On An FTP Server</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%2F20%2Fhow-to-properly-set-svn-svnexternals-property-in-svn-command-line%2F&amp;title=How%20To%20Properly%20Set%20SVN%20svn%3Aexternals%20Property%20In%20SVN%20Command%20Line" 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/2009/06/20/how-to-properly-set-svn-svnexternals-property-in-svn-command-line/feed/</wfw:commentRss> <slash:comments>30</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_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/03/18/mysql-indexing-considerations-of-implementing-a-priority-field-in-your-application/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
