Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 20A8E1337B96 for ; Wed, 11 May 2011 20:08:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 70653-03 for ; Wed, 11 May 2011 23:07:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp03.lnh.mail.rcn.net (smtp03.lnh.mail.rcn.net [207.172.157.103]) by mail.postgresql.org (Postfix) with ESMTP id 5FCAE1337B69 for ; Wed, 11 May 2011 20:07:58 -0300 (ADT) Received: from ms14.lnh.mail.rcn.net ([208.58.56.82]) by smtp02.lnh.mail.rcn.net with ESMTP; 11 May 2011 19:07:58 -0400 Received: (from ms14.lnh.mail.rcn.net [64.148.9.74]) by ms14.lnh.mail.rcn.net (MOS 4.2.3-GA) with HTTP/1.1 id BMI97980 (AUTH gnuoytr@rcn.com); Wed, 11 May 2011 19:07:57 -0400 (EDT) From: Subject: Re: Postgres refusing to use >1 core To: pgsql-performance@postgresql.org X-Mailer: Mirapoint Webmail Direct 4.2.3-GA MIME-Version: 1.0 In-Reply-To: <4DCB0802.9060505@peak6.com> References: <4DC81A3F020000250003D433@gw.wicourts.gov> <4DC81D56020000250003D438@gw.wicourts.gov> <4DC8B893.3060908@postnewspapers.com.au> <4DC9E7C5.9080309@postnewspapers.com.au> <4DCAB3A1.2090507@peak6.com> <201105111953.060147@ms14.lnh.mail.rcn.net> <4DCB0802.9060505@peak6.com> Message-Id: <201105112307.060223@ms14.lnh.mail.rcn.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 11 May 2011 19:07:57 -0400 (EDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/161 X-Sequence-Number: 43670 ---- Original message ---- >Date: Wed, 11 May 2011 17:04:50 -0500 >From: pgsql-performance-owner@postgresql.org (on behalf of Shaun Thomas ) >Subject: Re: [PERFORM] Postgres refusing to use >1 core >To: >Cc: Scott Marlowe ,Craig Ringer ,Aren Cambre , > >On 05/11/2011 02:53 PM, gnuoytr@rcn.com wrote: > >> So, the $64 question: how did you find an engagement where, to bend >> Shakespeare, "first thing we do, is kill all the coders" isn't >> required? > >It's just one of those things you have to explain. Not just how to fix >it, but *why* doing so fixes it. It's also not really a fair expectation >in a lot of ways. Even when a coder uses all SQL, their inexperience in >the engine can still ruin performance. We spend years getting to know >PostgreSQL, or just general DB techniques. They do the same with coding. >And unless they're a developer for a very graphics intensive project, >they're probably not well acquainted with set theory. > >Just today, I took a query like this: > > UPDATE customer c > SET c.login_counter = a.counter > FROM (SELECT session_id, count(*) as counter > FROM session > WHERE date_created >= CURRENT_DATE > GROUP BY session_id) a > WHERE c.process_date = CURRENT_DATE > AND c.customer_id = a.session_id > >And suggested this instead: > > CREATE TEMP TABLE tmp_login_counts AS > SELECT session_id, count(1) AS counter > FROM auth_token_arc > WHERE date_created >= CURRENT_DATE > GROUP BY session_id > > UPDATE reporting.customer c > SET login_counter = a.counter > FROM tmp_login_counts a > WHERE c.process_date = CURRENT_DATE > AND c.customer_id = a.session_id > >The original query, with our very large tables, ran for over *two hours* >thanks to a nested loop iterating over the subquery. My replacement ran >in roughly 30 seconds. If we were using a newer version of PG, we could >have used a CTE. But do you get what I mean? Temp tables are a fairly >common technique, but how would a coder know about CTEs? They're pretty >new, even to *us*. > >We hold regular Lunch'n'Learns for our developers to teach them the >good/bad of what they're doing, and that helps significantly. Even hours >later, I see them using the techniques I showed them. The one I'm >presenting soon is entitled '10 Ways to Ruin Performance' and they're >all specific examples taken from day-to-day queries and jobs here, all >from different categories of mistake. It's just a part of being a good DBA. > >-- >Shaun Thomas >OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 >312-676-8870 >sthomas@peak6.com > >______________________________________________ > >See http://www.peak6.com/email_disclaimer.php >for terms and conditions related to this email > >-- >Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) >To make changes to your subscription: >http://www.postgresql.org/mailpref/pgsql-performance You're (both) fortunate to have Suits and colleagues who are open to doing this A Better Way. Bless you. Regards, Robert