<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Using the extra() QuerySet modifier in Django for WeGoEat</title>
	<atom:link href="http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/</link>
	<description>Everything you&#039;ve ever thought, but never had the balls to say.</description>
	<lastBuildDate>Fri, 19 Mar 2010 00:53:14 -1000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ryankanno</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8785</link>
		<dc:creator>ryankanno</dc:creator>
		<pubDate>Fri, 26 Oct 2007 01:16:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8785</guid>
		<description>@Matt - 

Actually, last night I worked on denormalizing the tables and using a post.save signal, whenever a Review is added, the Restaurant instance associated saves itself which in turn updates a few columns, one being called &quot;average_review&quot; (just as Ross/Jeff suggested).  Thanks for the comment though - I love all the help the community provides; especially for us techies in remote places. :)</description>
		<content:encoded><![CDATA[<p>@Matt &#8211; </p>
<p>Actually, last night I worked on denormalizing the tables and using a post.save signal, whenever a Review is added, the Restaurant instance associated saves itself which in turn updates a few columns, one being called &#8220;average_review&#8221; (just as Ross/Jeff suggested).  Thanks for the comment though &#8211; I love all the help the community provides; especially for us techies in remote places. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8783</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 26 Oct 2007 00:14:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8783</guid>
		<description>Not sure that you want to be doing an AVG and/or COUNT on every request - might be better (at a certain point) to start using summary tables. Thanks for the post, though!</description>
		<content:encoded><![CDATA[<p>Not sure that you want to be doing an AVG and/or COUNT on every request &#8211; might be better (at a certain point) to start using summary tables. Thanks for the post, though!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trent</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8743</link>
		<dc:creator>Trent</dc:creator>
		<pubDate>Thu, 25 Oct 2007 13:09:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8743</guid>
		<description>Your website is very niceI just wish I could pick it apart and find all the little faults in it that you never thought about. Like you do to my things. But I can&#039;t</description>
		<content:encoded><![CDATA[<p>Your website is very niceI just wish I could pick it apart and find all the little faults in it that you never thought about. Like you do to my things. But I can&#8217;t</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Empty</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8717</link>
		<dc:creator>Empty</dc:creator>
		<pubDate>Thu, 25 Oct 2007 04:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8717</guid>
		<description>Nice post.  Extra is really useful but sometimes takes some work to get it to do what you want. I agree with Ross, I would likely denomalize this, especially if I expected to generate any significant traffic.</description>
		<content:encoded><![CDATA[<p>Nice post.  Extra is really useful but sometimes takes some work to get it to do what you want. I agree with Ross, I would likely denomalize this, especially if I expected to generate any significant traffic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Poulton</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8716</link>
		<dc:creator>Ross Poulton</dc:creator>
		<pubDate>Thu, 25 Oct 2007 04:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8716</guid>
		<description>:)

I can&#039;t take all the credit for it, the idea first came into my head when I saw it in the &lt;a href=&#039;http://www2.jeffcroft.com/blog/2007/may/28/lost-theoriescom-source-code-update/&#039; rel=&quot;nofollow&quot;&gt;Lost Theories source code that Jeff Croft made available&lt;/a&gt;.

It works very well, and it&#039;s the way I&#039;ve handle sorting by # comments and ratings on &lt;a href=&#039;http://www.djangosites.org/latest/&#039; rel=&quot;nofollow&quot;&gt;Django Sites&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p> <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I can&#8217;t take all the credit for it, the idea first came into my head when I saw it in the <a href='http://www2.jeffcroft.com/blog/2007/may/28/lost-theoriescom-source-code-update/' rel="nofollow">Lost Theories source code that Jeff Croft made available</a>.</p>
<p>It works very well, and it&#8217;s the way I&#8217;ve handle sorting by # comments and ratings on <a href='http://www.djangosites.org/latest/' rel="nofollow">Django Sites</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryankanno</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8712</link>
		<dc:creator>ryankanno</dc:creator>
		<pubDate>Thu, 25 Oct 2007 00:43:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8712</guid>
		<description>@Ross -

By far the best suggestion yet! :)  I hadn&#039;t even begun to think of denormalizing the database at all!  &lt;strike&gt;+1&lt;/strike&gt; +100 for Ross. :P  I&#039;ll be working on the signal tonight.  Gosh, community rocks!</description>
		<content:encoded><![CDATA[<p>@Ross -</p>
<p>By far the best suggestion yet! <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I hadn&#8217;t even begun to think of denormalizing the database at all!  <strike>+1</strike> +100 for Ross. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />   I&#8217;ll be working on the signal tonight.  Gosh, community rocks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Poulton</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8711</link>
		<dc:creator>Ross Poulton</dc:creator>
		<pubDate>Thu, 25 Oct 2007 00:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8711</guid>
		<description>That&#039;s a neat use of the extra() function; however I believe this may be a case for database de-normalisation. The most efficient way of doing this is probably to add an &#039;avg_rating&#039; field to your Restaurant model, and use a signal so that whenever a review is saved, you re-calculate the average rating for that Restaurant and save it directly on the model.

There is a huge upside to this de-normalised method: You can use sort_by() or limit() to only show restaurants that have a rating above 4, or sort them by rating.

Lastly, it should produce more portable code, as subselects may or may not work the same way on different database servers.</description>
		<content:encoded><![CDATA[<p>That&#8217;s a neat use of the extra() function; however I believe this may be a case for database de-normalisation. The most efficient way of doing this is probably to add an &#8216;avg_rating&#8217; field to your Restaurant model, and use a signal so that whenever a review is saved, you re-calculate the average rating for that Restaurant and save it directly on the model.</p>
<p>There is a huge upside to this de-normalised method: You can use sort_by() or limit() to only show restaurants that have a rating above 4, or sort them by rating.</p>
<p>Lastly, it should produce more portable code, as subselects may or may not work the same way on different database servers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryankanno</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8710</link>
		<dc:creator>ryankanno</dc:creator>
		<pubDate>Wed, 24 Oct 2007 23:31:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8710</guid>
		<description>I definitely agree that the SQL makes subselects for every row.  

Since I&#039;m no database guru, I&#039;ll profile it under SQL analyzer to see how bad/optimized it is.  Yet, I don&#039;t think Django is the problem here at all.  If anything, it&#039;s me as the developer, and if you were trying to be nice about it... Thanks! :) If I knew the optimized SQL to write, I would. ;)

Maybe the optimal thing to do is to perform the query to retrieve the objects, then perform the average call, then merge the data QuerySet&#039;s together... :P</description>
		<content:encoded><![CDATA[<p>I definitely agree that the SQL makes subselects for every row.  </p>
<p>Since I&#8217;m no database guru, I&#8217;ll profile it under SQL analyzer to see how bad/optimized it is.  Yet, I don&#8217;t think Django is the problem here at all.  If anything, it&#8217;s me as the developer, and if you were trying to be nice about it&#8230; Thanks! <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If I knew the optimized SQL to write, I would. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Maybe the optimal thing to do is to perform the query to retrieve the objects, then perform the average call, then merge the data QuerySet&#8217;s together&#8230; <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julian</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8709</link>
		<dc:creator>Julian</dc:creator>
		<pubDate>Wed, 24 Oct 2007 22:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8709</guid>
		<description>It is definitely an improvement. But showing it as a good solution and blog about it is not. This SQL still makes subselects, for every single row. The real problem is Django in this case, we should focus on that, instead of praising workarounds which circumvent real SQL solutions.</description>
		<content:encoded><![CDATA[<p>It is definitely an improvement. But showing it as a good solution and blog about it is not. This SQL still makes subselects, for every single row. The real problem is Django in this case, we should focus on that, instead of praising workarounds which circumvent real SQL solutions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryankanno</title>
		<link>http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/comment-page-1/#comment-8706</link>
		<dc:creator>ryankanno</dc:creator>
		<pubDate>Wed, 24 Oct 2007 20:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.localkinegrinds.com/2007/10/24/using-the-extra-queryset-modifier-in-django-for-wegoeat/#comment-8706</guid>
		<description>@Benjamin:

I think that at the end of the day, this is an improvement (at least performance wise) - but I can see how it is arguably so.  I agree that the SQL is being executed with the subquery, but I think you have to look at where the query is being optimized.  

In the subquery extra() clause, the database is handling the optimization for you; ie we&#039;re letting the database do what it&#039;s good at.  As to how optimized the MySQL query analyzer is for its B-tree is up for debate (I&#039;m no database expert).  I think letting the database handle this versus making &quot;N&quot; number of MySQL AVG() calls (while retrieving connections, etc) is a definite improvement performance-wise.  

However, as I said earlier, I think it can be debated since this type of SQL injection obviously leads to maintenance hell in large projects. :)   But then again, since I&#039;m no database guru, this could all be total bs. :P  As for your join and AVG() function call, maybe someone can pitch in and set &lt;strike&gt;us&lt;/strike&gt; me straight. :)

&lt;strong&gt;Update:&lt;/strong&gt; @Benjamin: Read my previous comment as I think your comment was where the templatetag is going.  </description>
		<content:encoded><![CDATA[<p>@Benjamin:</p>
<p>I think that at the end of the day, this is an improvement (at least performance wise) &#8211; but I can see how it is arguably so.  I agree that the SQL is being executed with the subquery, but I think you have to look at where the query is being optimized.  </p>
<p>In the subquery extra() clause, the database is handling the optimization for you; ie we&#8217;re letting the database do what it&#8217;s good at.  As to how optimized the MySQL query analyzer is for its B-tree is up for debate (I&#8217;m no database expert).  I think letting the database handle this versus making &#8220;N&#8221; number of MySQL AVG() calls (while retrieving connections, etc) is a definite improvement performance-wise.  </p>
<p>However, as I said earlier, I think it can be debated since this type of SQL injection obviously leads to maintenance hell in large projects. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />    But then again, since I&#8217;m no database guru, this could all be total bs. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />   As for your join and AVG() function call, maybe someone can pitch in and set <strike>us</strike> me straight. <img src='http://blog.localkinegrinds.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Update:</strong> @Benjamin: Read my previous comment as I think your comment was where the templatetag is going.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
