<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Railers Need To Stop Not Caring About The Database</title>
	<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/</link>
	<description>Because programming should be fun</description>
	<pubDate>Tue, 08 Jul 2008 21:04:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: Dan</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-574</link>
		<author>Dan</author>
		<pubDate>Thu, 24 Apr 2008 14:58:59 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-574</guid>
					<description>How can we be so unrespectful about databases? I've been working in Rails since 1 year and never I looked at the indexes that are created (or not). Shame on me...</description>
		<content:encoded><![CDATA[<p>How can we be so unrespectful about databases? I&#8217;ve been working in Rails since 1 year and never I looked at the indexes that are created (or not). Shame on me&#8230;</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Shai</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-575</link>
		<author>Shai</author>
		<pubDate>Thu, 24 Apr 2008 15:21:14 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-575</guid>
					<description>Nice article.  I'm working with databases full time so I definitely appreciate indexes and using correct joins.  Jamis Buck covered this issue a while back here (should be mandatory reading for rails developers) http://www.therailsway.com/2006/11/21/tracks-part-4</description>
		<content:encoded><![CDATA[<p>Nice article.  I&#8217;m working with databases full time so I definitely appreciate indexes and using correct joins.  Jamis Buck covered this issue a while back here (should be mandatory reading for rails developers) <a href="http://www.therailsway.com/2006/11/21/tracks-part-4" rel="nofollow">http://www.therailsway.com/2006/11/21/tracks-part-4</a></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Rowan</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-576</link>
		<author>Rowan</author>
		<pubDate>Thu, 24 Apr 2008 15:43:34 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-576</guid>
					<description>Some related reading, I did a presentation on ActiveRecord gotchas with include/select/find_by_sql. Not only joins, but limiting your selects are really important here http://work.rowanhick.com/2008/02/12/how-to-avoid-hanging-yourself-with-rails/</description>
		<content:encoded><![CDATA[<p>Some related reading, I did a presentation on ActiveRecord gotchas with include/select/find_by_sql. Not only joins, but limiting your selects are really important here <a href="http://work.rowanhick.com/2008/02/12/how-to-avoid-hanging-yourself-with-rails/" rel="nofollow">http://work.rowanhick.com/2008/02/12/how-to-avoid-hanging-yourself-with-rails/</a></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Robin Watson</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-577</link>
		<author>Robin Watson</author>
		<pubDate>Thu, 24 Apr 2008 16:17:56 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-577</guid>
					<description>It's very true that ActiveRecord causes too many Rails coders to not think about the database. ActiveRecord can be painfully slow

One question: Is it right that in many cases, switching an outer join to an inner join could cause different data to be selected from the database?</description>
		<content:encoded><![CDATA[<p>It&#8217;s very true that ActiveRecord causes too many Rails coders to not think about the database. ActiveRecord can be painfully slow</p>
<p>One question: Is it right that in many cases, switching an outer join to an inner join could cause different data to be selected from the database?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: kabari</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-578</link>
		<author>kabari</author>
		<pubDate>Thu, 24 Apr 2008 16:34:59 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-578</guid>
					<description>@Robin:  yes, they can provide different results. Here's a pretty good write up on the subject: http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN.html

This is why I like the stuff that RedHill on Rails has. Allowing me to add my indexes and foreign key associations in my migrations.</description>
		<content:encoded><![CDATA[<p>@Robin:  yes, they can provide different results. Here&#8217;s a pretty good write up on the subject: <a href="http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN.html" rel="nofollow">http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN.html</a></p>
<p>This is why I like the stuff that RedHill on Rails has. Allowing me to add my indexes and foreign key associations in my migrations.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Clemens Kofler</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-579</link>
		<author>Clemens Kofler</author>
		<pubDate>Thu, 24 Apr 2008 17:19:24 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-579</guid>
					<description>You seem to have run into the same problem like many other developers. Just because you're doing Rails, that doesn't mean you don't have to understand the works _behind_ Rails. Every web developer working with any programming language or framework should be at least familiar with the basics of joins (i.e. differences between outer and inner joins), basic database optimization (like using indexes) and how to track inefficient queries (using EXPLAIN in MySQL, for example).
Read. Learn. Remember. ;-)</description>
		<content:encoded><![CDATA[<p>You seem to have run into the same problem like many other developers. Just because you&#8217;re doing Rails, that doesn&#8217;t mean you don&#8217;t have to understand the works _behind_ Rails. Every web developer working with any programming language or framework should be at least familiar with the basics of joins (i.e. differences between outer and inner joins), basic database optimization (like using indexes) and how to track inefficient queries (using EXPLAIN in MySQL, for example).<br />
Read. Learn. Remember. <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Railers Need To Stop Not Caring About The Database : Hendrik Mans</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-580</link>
		<author>Railers Need To Stop Not Caring About The Database : Hendrik Mans</author>
		<pubDate>Thu, 24 Apr 2008 17:41:50 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-580</guid>
					<description>[...] other news, most Rails apps are slow because the developers are ignorant of database basics. Not slamming the blog's author, but it is a good example of how easy it is to mess up a Rails [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] other news, most Rails apps are slow because the developers are ignorant of database basics. Not slamming the blog&#8217;s author, but it is a good example of how easy it is to mess up a Rails [&#8230;]</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Joe Grossberg</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-581</link>
		<author>Joe Grossberg</author>
		<pubDate>Thu, 24 Apr 2008 17:43:07 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-581</guid>
					<description>On the other hand, you lose a lot of the ActiveRecord advantages if you pay *too much* attention to the database. Don't optimize prematurely. But yeah -- if there's slowness, tail the db log and look for inefficiencies.</description>
		<content:encoded><![CDATA[<p>On the other hand, you lose a lot of the ActiveRecord advantages if you pay *too much* attention to the database. Don&#8217;t optimize prematurely. But yeah &#8212; if there&#8217;s slowness, tail the db log and look for inefficiencies.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Optimizing ActiveRecord :includes with :select &#124; trapdoor1</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-584</link>
		<author>Optimizing ActiveRecord :includes with :select &#124; trapdoor1</author>
		<pubDate>Thu, 24 Apr 2008 17:51:55 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-584</guid>
					<description>[...] have just read two posts (here and here), both of them discussing the sometimes formidable challenges faced when attempting to [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] have just read two posts (here and here), both of them discussing the sometimes formidable challenges faced when attempting to [&#8230;]</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: typicalrunt</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-585</link>
		<author>typicalrunt</author>
		<pubDate>Thu, 24 Apr 2008 18:02:50 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-585</guid>
					<description>After reading this post and seeing the comment "don't optimize prematurely", many database developers and seasoned programmers are shaking their heads right now.  

I've seen many a code (in rails, python, or any language for that matter) that uses an ORM library which doesn't generate efficient SQL.  This is fine, as long as those developer using the ORM know what the generated SQL is and how to make it more efficent.  The guys from iBATIS have a good idea of how to interface with a DB, but it's missing the glamour of ActiveRecord.  Sometimes custom SQL is the best option, regardless of how ugly it makes the ORM/ActiveRecord code look.</description>
		<content:encoded><![CDATA[<p>After reading this post and seeing the comment &#8220;don&#8217;t optimize prematurely&#8221;, many database developers and seasoned programmers are shaking their heads right now.  </p>
<p>I&#8217;ve seen many a code (in rails, python, or any language for that matter) that uses an ORM library which doesn&#8217;t generate efficient SQL.  This is fine, as long as those developer using the ORM know what the generated SQL is and how to make it more efficent.  The guys from iBATIS have a good idea of how to interface with a DB, but it&#8217;s missing the glamour of ActiveRecord.  Sometimes custom SQL is the best option, regardless of how ugly it makes the ORM/ActiveRecord code look.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Pazu</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-587</link>
		<author>Pazu</author>
		<pubDate>Thu, 24 Apr 2008 20:25:14 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-587</guid>
					<description>Rails DOES care about the database, in fact Rails cares more than most other web frameworks out there. ActiveRecord is designed to keep you CLOSE to SQL, so you never forget that in the end that's what being executed.

You should think of ActiveRecord as something to help you construct and issue SQL commands that would be otherwise complex and troublesome to write, not as an excuse to not know anything about your database.</description>
		<content:encoded><![CDATA[<p>Rails DOES care about the database, in fact Rails cares more than most other web frameworks out there. ActiveRecord is designed to keep you CLOSE to SQL, so you never forget that in the end that&#8217;s what being executed.</p>
<p>You should think of ActiveRecord as something to help you construct and issue SQL commands that would be otherwise complex and troublesome to write, not as an excuse to not know anything about your database.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: NIck Fessel</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-588</link>
		<author>NIck Fessel</author>
		<pubDate>Fri, 25 Apr 2008 01:15:58 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-588</guid>
					<description>Rails is a calculator, and the database is math. Teach a child math before giving them a calculator!</description>
		<content:encoded><![CDATA[<p>Rails is a calculator, and the database is math. Teach a child math before giving them a calculator!</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: florentin</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-589</link>
		<author>florentin</author>
		<pubDate>Fri, 25 Apr 2008 03:40:29 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-589</guid>
					<description>I got exactly the opposite from you I do a great merise relationship model (i try ...) but a sh***s rails models...
I learn merise with a teacher that doesn't know ruby nor rails ...(and who think c# THE programming language ..)so i start with complicated diagrams but poor(inefficient) relation in my apps.
well sometimes it's hard to make rails/relationship diagrams match...</description>
		<content:encoded><![CDATA[<p>I got exactly the opposite from you I do a great merise relationship model (i try &#8230;) but a sh***s rails models&#8230;<br />
I learn merise with a teacher that doesn&#8217;t know ruby nor rails &#8230;(and who think c# THE programming language ..)so i start with complicated diagrams but poor(inefficient) relation in my apps.<br />
well sometimes it&#8217;s hard to make rails/relationship diagrams match&#8230;</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-590</link>
		<author>Michael</author>
		<pubDate>Fri, 25 Apr 2008 12:33:06 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-590</guid>
					<description>Indexes are good for more than speeding up SELECTs, as I'm sure you're aware.  One ActiveRecord feature bit me pretty nicely.  The validates_uniqueness_of constraint is definitely not guaranteed as the skateboard book says on p. 369.  Further, it does a SELECT every time it does an INSERT.  This can be costly.  A "guaranteed" way to enforce uniqueness and to help with efficiency is to create a unique index on the field(s) in question at the database level.  You'll need to trap the database error yourself though.  YMMV.</description>
		<content:encoded><![CDATA[<p>Indexes are good for more than speeding up SELECTs, as I&#8217;m sure you&#8217;re aware.  One ActiveRecord feature bit me pretty nicely.  The validates_uniqueness_of constraint is definitely not guaranteed as the skateboard book says on p. 369.  Further, it does a SELECT every time it does an INSERT.  This can be costly.  A &#8220;guaranteed&#8221; way to enforce uniqueness and to help with efficiency is to create a unique index on the field(s) in question at the database level.  You&#8217;ll need to trap the database error yourself though.  YMMV.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-591</link>
		<author>Frank</author>
		<pubDate>Fri, 25 Apr 2008 16:20:39 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-591</guid>
					<description>Thanks everyone for your comments

The morale of the story for me is that you cannot blindly delegate everything that is "database related" to ActiveRecord or any other O/R mapping tool. Maybe one day tools like ActiveRecord will be so advanced that playing at the database level will not be a necessity anymore ... but this time hasn't come yet. Until then we have to keep an eye on the generated queries from time to time as well as do some optimizing when our app ask for it.

You know what? Before switching to Rails I was a convinced .NET (1.1) developer that used to write all his SQL queries by hand. I remember how much it was repetitive and tedious to do this for every single project. I hated it so much that I made the mistake of embracing ActiveRecord with too much passion when I made the switch to Rails. There is an old saying that love is blind... I should have think about it.</description>
		<content:encoded><![CDATA[<p>Thanks everyone for your comments</p>
<p>The morale of the story for me is that you cannot blindly delegate everything that is &#8220;database related&#8221; to ActiveRecord or any other O/R mapping tool. Maybe one day tools like ActiveRecord will be so advanced that playing at the database level will not be a necessity anymore &#8230; but this time hasn&#8217;t come yet. Until then we have to keep an eye on the generated queries from time to time as well as do some optimizing when our app ask for it.</p>
<p>You know what? Before switching to Rails I was a convinced .NET (1.1) developer that used to write all his SQL queries by hand. I remember how much it was repetitive and tedious to do this for every single project. I hated it so much that I made the mistake of embracing ActiveRecord with too much passion when I made the switch to Rails. There is an old saying that love is blind&#8230; I should have think about it.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Neil Wilson</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-592</link>
		<author>Neil Wilson</author>
		<pubDate>Sun, 27 Apr 2008 10:44:21 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-592</guid>
					<description>You should ignore the database, until you can't ignore it any longer. I've seen the SQL that Rails has generated and figured I could write better by hand. But then I've seen the assembler generated by C compilers and reckoned that I could write better by hand. That is not the point though. Ultimately what you are missing here is a tool on the database that *tells* you when you should put an index on something. I've alwasy been surpirsed at how poor the tooling is at the database level. Perhaps there is too much 'hand optimisation' going on, not too ittle</description>
		<content:encoded><![CDATA[<p>You should ignore the database, until you can&#8217;t ignore it any longer. I&#8217;ve seen the SQL that Rails has generated and figured I could write better by hand. But then I&#8217;ve seen the assembler generated by C compilers and reckoned that I could write better by hand. That is not the point though. Ultimately what you are missing here is a tool on the database that *tells* you when you should put an index on something. I&#8217;ve alwasy been surpirsed at how poor the tooling is at the database level. Perhaps there is too much &#8216;hand optimisation&#8217; going on, not too ittle</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: AkitaOnRails</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-593</link>
		<author>AkitaOnRails</author>
		<pubDate>Sun, 27 Apr 2008 17:58:51 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-593</guid>
					<description>Do you really know the difference between 'inner' and 'outer' joins? They are quite striking and you can't replace one for the other with no adequate reasoning. Rails jas both :include and :joins keyword (and :joins accept an array or strings as well) and you have to do the reasoning on what do you want. It seems to me that you don't know those differences and what do you really want.</description>
		<content:encoded><![CDATA[<p>Do you really know the difference between &#8216;inner&#8217; and &#8216;outer&#8217; joins? They are quite striking and you can&#8217;t replace one for the other with no adequate reasoning. Rails jas both :include and :joins keyword (and :joins accept an array or strings as well) and you have to do the reasoning on what do you want. It seems to me that you don&#8217;t know those differences and what do you really want.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-594</link>
		<author>Frank</author>
		<pubDate>Mon, 28 Apr 2008 13:01:13 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-594</guid>
					<description>@Akita,

*sigh*... enough with this already... this is getting on my nerves. I know the difference between INNER and OUTER. A left outer join includes the rows in the right tables even if there are no match (when it happens the columns in the right table will all be filled with NULLs) while an INNER join only returns the rows "that matches". In my specific case it just could not happen that a row from the right table does not match a row from the left. 

Is this explanation convince you that I know what joins are or do you still need more clarifications?</description>
		<content:encoded><![CDATA[<p>@Akita,</p>
<p>*sigh*&#8230; enough with this already&#8230; this is getting on my nerves. I know the difference between INNER and OUTER. A left outer join includes the rows in the right tables even if there are no match (when it happens the columns in the right table will all be filled with NULLs) while an INNER join only returns the rows &#8220;that matches&#8221;. In my specific case it just could not happen that a row from the right table does not match a row from the left. </p>
<p>Is this explanation convince you that I know what joins are or do you still need more clarifications?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Green Rails</title>
		<link>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-595</link>
		<author>Green Rails</author>
		<pubDate>Tue, 29 Apr 2008 23:20:36 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/railers-need-to-stop-not-caring-about-the-database/#comment-595</guid>
					<description>This is so very true: Rails is pretty damned magic, but sometimes the rubber meets the road.  

SQL makes me laugh since a design goal was to be usable by typical business people ... yeah, right.  I consider myself a black-belt SQLer (arguable, but invite smackdowns from any interested combatant), and despite my &#62;20 years experience with the language, I still find SQL to be the most infuriating and obtuse syntax on the face of the earth (this includes C and C++, as well as perl).  Rails insulates us in perhaps 90% of normal cases from the gnarly details.  The problem is those 10% of the rest.

I wonder if there's a need for a Rails "sniff check" of a given controller action, or query?  Wouldn't it be cool if Rails warned "this query takes a really long time -- try these things before hiring a $250/hour consultant: 1) use eager loading, 2) check to make sure these columns are indexed ("foo", "bar", "fubar"), and 3) learn SQL, you lazy, incompetent so-called software engineer.  OK, maybe just 2 things.

We dealt with this issue in the last few days for a really complicated polymorphic query.  It is as real as it gets.  Rails doesn't solve all problems ... yet.</description>
		<content:encoded><![CDATA[<p>This is so very true: Rails is pretty damned magic, but sometimes the rubber meets the road.  </p>
<p>SQL makes me laugh since a design goal was to be usable by typical business people &#8230; yeah, right.  I consider myself a black-belt SQLer (arguable, but invite smackdowns from any interested combatant), and despite my &gt;20 years experience with the language, I still find SQL to be the most infuriating and obtuse syntax on the face of the earth (this includes C and C++, as well as perl).  Rails insulates us in perhaps 90% of normal cases from the gnarly details.  The problem is those 10% of the rest.</p>
<p>I wonder if there&#8217;s a need for a Rails &#8220;sniff check&#8221; of a given controller action, or query?  Wouldn&#8217;t it be cool if Rails warned &#8220;this query takes a really long time &#8212; try these things before hiring a $250/hour consultant: 1) use eager loading, 2) check to make sure these columns are indexed (&#8221;foo&#8221;, &#8220;bar&#8221;, &#8220;fubar&#8221;), and 3) learn SQL, you lazy, incompetent so-called software engineer.  OK, maybe just 2 things.</p>
<p>We dealt with this issue in the last few days for a really complicated polymorphic query.  It is as real as it gets.  Rails doesn&#8217;t solve all problems &#8230; yet.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
