<?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: Creating a counter_cache column</title>
	<atom:link href="http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/</link>
	<description>On Ruby, software and the Internet</description>
	<lastBuildDate>Wed, 21 Jul 2010 20:03:10 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jerrett</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-401</link>
		<dc:creator>Jerrett</dc:creator>
		<pubDate>Wed, 05 Aug 2009 21:41:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-401</guid>
		<description>&quot;I think most people wouldn’t know how to start by creating temp tables and pushing/pulling the data via a migration.&quot; 

... And these people are writing code? :(</description>
		<content:encoded><![CDATA[<p>&#8220;I think most people wouldn’t know how to start by creating temp tables and pushing/pulling the data via a migration.&#8221; </p>
<p>&#8230; And these people are writing code? <img src='http://www.mikeperham.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Watts</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-359</link>
		<dc:creator>Andy Watts</dc:creator>
		<pubDate>Thu, 04 Jun 2009 16:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-359</guid>
		<description>Thanks for this.
Totally agree, doing this through AR gets slow quickly.</description>
		<content:encoded><![CDATA[<p>Thanks for this.<br />
Totally agree, doing this through AR gets slow quickly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniel</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-348</link>
		<dc:creator>daniel</dc:creator>
		<pubDate>Tue, 26 May 2009 16:06:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-348</guid>
		<description>Excellent! Used it for a table with about 500000 entries, an it just took a minute. Instead of apprx. 2 hours, which is the time required to iterate over the objects. Thanks!</description>
		<content:encoded><![CDATA[<p>Excellent! Used it for a table with about 500000 entries, an it just took a minute. Instead of apprx. 2 hours, which is the time required to iterate over the objects. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jfromm</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-265</link>
		<dc:creator>jfromm</dc:creator>
		<pubDate>Tue, 16 Dec 2008 09:45:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-265</guid>
		<description>Yes, it is not only a reasonable way  to speed up code, it is also useful to sort items. I wrote about it &lt;a href=&quot;http://4loc.wordpress.com/2008/10/13/update-of-counter-cache-columns/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Yes, it is not only a reasonable way  to speed up code, it is also useful to sort items. I wrote about it <a href="http://4loc.wordpress.com/2008/10/13/update-of-counter-cache-columns/" rel="nofollow">here</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chip Ramsey</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-224</link>
		<dc:creator>Chip Ramsey</dc:creator>
		<pubDate>Wed, 22 Oct 2008 17:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-224</guid>
		<description>Same concept for PostgresSQL:

UPDATE accounts
SET users_count = comm.the_count
FROM (select account_id, count(*) as the_count from users where is_active = &#039;t&#039; group by account_id) as comm
WHERE accounts.id = comm.account_id;</description>
		<content:encoded><![CDATA[<p>Same concept for PostgresSQL:</p>
<p>UPDATE accounts<br />
SET users_count = comm.the_count<br />
FROM (select account_id, count(*) as the_count from users where is_active = &#8216;t&#8217; group by account_id) as comm<br />
WHERE accounts.id = comm.account_id;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Andersson</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-54</link>
		<dc:creator>Erik Andersson</dc:creator>
		<pubDate>Sun, 17 Feb 2008 21:12:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-54</guid>
		<description>This was exactly what i needed! Thank you!</description>
		<content:encoded><![CDATA[<p>This was exactly what i needed! Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Owens</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-39</link>
		<dc:creator>Josh Owens</dc:creator>
		<pubDate>Tue, 22 Jan 2008 06:32:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-39</guid>
		<description>Mike,

I see your point, but I would worry about people who *haven&#039;t* implemented a counter cache and have 2 million objects that are associated.  I think the speed up a counter cache provides will be found much sooner than 2 million objects.

I think most people wouldn&#039;t know how to start by creating temp tables and pushing/pulling the data via a migration.
Just my $0.02</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>I see your point, but I would worry about people who *haven&#8217;t* implemented a counter cache and have 2 million objects that are associated.  I think the speed up a counter cache provides will be found much sooner than 2 million objects.</p>
<p>I think most people wouldn&#8217;t know how to start by creating temp tables and pushing/pulling the data via a migration.<br />
Just my $0.02</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mperham</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-31</link>
		<dc:creator>mperham</dc:creator>
		<pubDate>Fri, 28 Dec 2007 18:46:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-31</guid>
		<description>Josh, please read my blog posting over again.  You are doing exactly what I said: iterating through each Recipe one at a time and initializing its counter value.  If you have 2,000,000 recipes, this will require 2,000,000 queries and a lot of memory (since you will be holding 2m recipes in memory after the find(:all)).  The query I give above will do all that work in a single query with no memory overhead (all the hard work is pushed to the database layer).</description>
		<content:encoded><![CDATA[<p>Josh, please read my blog posting over again.  You are doing exactly what I said: iterating through each Recipe one at a time and initializing its counter value.  If you have 2,000,000 recipes, this will require 2,000,000 queries and a lot of memory (since you will be holding 2m recipes in memory after the find(:all)).  The query I give above will do all that work in a single query with no memory overhead (all the hard work is pushed to the database layer).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Owens</title>
		<link>http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/comment-page-1/#comment-30</link>
		<dc:creator>Josh Owens</dc:creator>
		<pubDate>Fri, 28 Dec 2007 17:51:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/#comment-30</guid>
		<description>Why use MySQL directly?  Just use migrations...

http://josh.the-owens.com/archives/2007/11/03/rails-edge-change-how-to-add-a-counter-cache-to-an-existing-db-table/</description>
		<content:encoded><![CDATA[<p>Why use MySQL directly?  Just use migrations&#8230;</p>
<p><a href="http://josh.the-owens.com/archives/2007/11/03/rails-edge-change-how-to-add-a-counter-cache-to-an-existing-db-table/" rel="nofollow">http://josh.the-owens.com/archives/2007/11/03/rails-edge-change-how-to-add-a-counter-cache-to-an-existing-db-table/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
