<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>20bits - Latest Comments in 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.disqus.com/</link><description></description><language>en</language><lastBuildDate>Wed, 24 Jun 2009 19:11:09 -0000</lastBuildDate><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-11705390</link><description>Cool, Thanks!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nick Yeoman</dc:creator><pubDate>Wed, 24 Jun 2009 19:11:09 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-9192879</link><description>I liked a lot your post but wish to as one question, about a problem I need to solve.&lt;br&gt;I am facing a situation wher I have to query a database for the countries names, then, when a client select a country, I show the states (regions) of this country and, finally, when he selects one of these regions, I need to show all the cities of this region.&lt;br&gt;I ask:&lt;br&gt;What should I use: &lt;br&gt;one table for the countries with countries names and countries codes;&lt;br&gt;one table for the regions with regions names and codes, for each country;&lt;br&gt;one table for the cities for that country.&lt;br&gt;or, it's best to have only one table with all that data and perform all queries in that table (more than 2,000,000 records)?&lt;br&gt;&lt;br&gt;Thanks</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sergio</dc:creator><pubDate>Sun, 10 May 2009 20:47:57 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-8688601</link><description>good post. One way I find make a big difference is using group by rather than distinct when it's possible</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Henry</dc:creator><pubDate>Sat, 25 Apr 2009 14:35:17 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-5828337</link><description>Great article.  I'm trying to take my MySql skills to the next level and this is the kind of stuff I want to learn.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nate</dc:creator><pubDate>Tue, 03 Feb 2009 23:49:44 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-5070742</link><description>Thanks for your list! Also, I was so free to do my own post on some basic and advanced mysql tuning tips!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Zen of Linux</dc:creator><pubDate>Mon, 12 Jan 2009 06:04:59 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793244</link><description>Angsuman,&lt;br&gt;&lt;br&gt;Cool.  I'll check it out.&lt;br&gt;&lt;br&gt;As for the ORM stuff, I know, but I don't care that much.  My interests skew towards large, denormalized data storage, anyhow.  Building the next great Rails app ain't my thing.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Thu, 16 Oct 2008 16:57:31 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793239</link><description>Nice tips. I too have written some tips in not so recent past on my blog covering how to handle frequent inserts on a database maximized for reading like a blog using MyISAM.&lt;br&gt;BTW: Your tip on eliminating artificial primary key has issues with most ORM frameworks like Hibernate.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Angsuman Chakraborty</dc:creator><pubDate>Tue, 09 Sep 2008 12:18:43 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793238</link><description>great tips!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Werner</dc:creator><pubDate>Mon, 08 Sep 2008 12:44:28 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793242</link><description>Thanks for the list. Great perspective.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Calgary Web Design</dc:creator><pubDate>Thu, 28 Aug 2008 12:59:56 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793241</link><description>Hey Jesse-- I just wanted to let you know that I've been doing a fair deal of schema-ing (and scheming) at my new job and I've been using this article like a bible and sharing it with my colleagues. Thanks! ^^</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mitcho</dc:creator><pubDate>Tue, 26 Aug 2008 02:11:42 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793245</link><description>These are some fantastic tips, thanks man!&lt;br&gt;Just ordered myself a copy of the book High Performance MySQL (Arjen Lentz, Peter Zaitsev, Vadim Tkachenko), can't wait, working on a project that needs massive amounts of data output from MySQL and it seems I'll be using this new knowledge to save the company from having to buy bigger servers.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Re@PeR</dc:creator><pubDate>Tue, 29 Jul 2008 05:15:07 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793237</link><description>I know the post is like a year old. But I think that it is the single best post on mysql optimization.&lt;br&gt;Concise and to the point and practical. Good job.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">paan</dc:creator><pubDate>Tue, 08 Jul 2008 02:14:51 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793243</link><description>Hello, How write sql query for mysql, selet top 10 ?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hoteles Mar del Plata</dc:creator><pubDate>Fri, 04 Jul 2008 11:12:09 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793240</link><description>I've read a lot of the "MySQL" Optimization guides and yours is the best so far as a single post. Most of them have gone over "Indexing" or totally skewed the guide you end up screwing yourself. &lt;br&gt;&lt;br&gt;I use parenthesis when I'm trying to do two compares on a column ie: (`date` &amp;gt;= 'xxxx' AND `date` &amp;lt;= 'yyyy'). Just make me feel comfortable with grouping it like that.&lt;br&gt;&lt;br&gt;As for the other things - I think you have given me a lot of stuff to help me in my job that I start in 2 weeks. I leave the current job tomorrow (friday), where even I know my read calls are really quick, but i can see it being at least 2x faster with these tips.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ellisgl</dc:creator><pubDate>Thu, 08 May 2008 21:21:42 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793236</link><description>ken,&lt;br&gt;&lt;br&gt;Yeah.  I don't know what version what around when I wrote this article -- but that was 11 months ago.  It'd also be unfortunate if Rails flipped out by default (i.e., required :id =&amp;gt; false), since, AFAIK, Rails is supposed to be about "convention no configuration."</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Tue, 18 Mar 2008 15:42:44 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793235</link><description>OK, I guess I have to give you that.  We do pass :id=&amp;gt;false (which I think has been around basically forever) to the join table, but it's true that some Rails features flip out on :id=&amp;gt;false tables (even with 2.0.2).  I don't think I've seen any outflipping for join tables in particular, but I wouldn't bet against it.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ken</dc:creator><pubDate>Tue, 18 Mar 2008 15:19:09 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793234</link><description>ken,&lt;br&gt;&lt;br&gt;I think when I wrote this Rails would flip out if even the join table didn't have its own auto incrementing primary key.  This might have changed, but it's also possible I was wrong.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Tue, 18 Mar 2008 13:51:28 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793233</link><description>Jesse:&lt;br&gt;&lt;br&gt;Rails doesn't support composite keys for model classes, but posts_tags here is just a join table, and it's fine with composite keys here -- in fact I'm pretty sure it's the default.  We do precisely this in several places, and I don't remember needing to do anything special.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ken</dc:creator><pubDate>Tue, 18 Mar 2008 13:44:53 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793232</link><description>The missing thing still is how to make sql queries faster</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mysql freak</dc:creator><pubDate>Tue, 26 Feb 2008 12:10:47 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793231</link><description>Very nice article Jesse. Sound, practical advice well presented and argued. The advanced topics such as benchmarking and profiling are areas I haven't really delved into yet so thanks alot for the pointers. p.s. I don't think Justin Silverton has indexed his `retort` column as his comeback query is taking a long time to run.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Matt Carpenter</dc:creator><pubDate>Sat, 03 Nov 2007 20:34:07 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793230</link><description>Thank you for sharing!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Wahoo</dc:creator><pubDate>Fri, 05 Oct 2007 19:52:27 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793229</link><description>Zerd,&lt;br&gt;&lt;br&gt;I'm pretty sure horizontal partitioning is when you split according to rows and vertical is when you split by column.  So, e.g., if you have an accounting system and all accounts in a given year are in their own table, that'd be horizontal partitioning.  What I've described is vertical partitioning.&lt;br&gt;&lt;br&gt;As for your query, I can take a guess.  I'd wager that you're using MyISAM tables, in which case count(*) is opimized away.  Your indices might also be messed up.  That is, if com.entry isn't an index then joining becomes more expensive.  I presume entries.id and com.id are primary keys, so they're automatically indexed.&lt;br&gt;&lt;br&gt;It might even be faster to do: SELECT title, c.comments FROM entries JOIN (SELECT entry, COUNT(*) as comments FROM comments GROUP BY (comments.entry)) c ON c.entry = entries.id;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Fri, 06 Jul 2007 16:43:43 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793228</link><description>According to Jay Pipes, your example (by splitting columns) is horizontal. Making more tables (splitting and merging) is vertical.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Zerd</dc:creator><pubDate>Sun, 01 Jul 2007 01:22:02 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793227</link><description>I was trying to rewrite a sub-query into a join query, but it wouldn't run any faster (actually a lot slower). I'm tryign to fetch number of comments for each blog entry. It goes like this:&lt;br&gt;&lt;br&gt;SELECT title, COUNT(com.id) comments FROM entries LEFT JOIN com ON entries.id = com.entry GROUP BY entries.id ORDER BY entries.time DESC LIMIT 10&lt;br&gt;&lt;br&gt;The subquery just selected COUNT(*) from comments where id = entries.id.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Zerd</dc:creator><pubDate>Sun, 01 Jul 2007 00:30:32 -0000</pubDate></item><item><title>Re: 10 Tips for Optimizing MySQL Queries (That don&amp;#8217;t suck) | 20bits</title><link>http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/#comment-3793226</link><description>Thanks for sharing!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">freelancer</dc:creator><pubDate>Tue, 26 Jun 2007 10:28:54 -0000</pubDate></item></channel></rss>