Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 211C11337F89 for ; Wed, 15 Sep 2010 03:32:51 -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 06396-08 for ; Wed, 15 Sep 2010 06:32:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from fep17.mx.upcmail.net (fep17.mx.upcmail.net [62.179.121.37]) by mail.postgresql.org (Postfix) with ESMTP id AB1021337F85 for ; Wed, 15 Sep 2010 03:32:42 -0300 (ADT) Received: from edge04.upcmail.net ([192.168.13.239]) by viefep17-int.chello.at (InterMail vM.8.01.02.02 201-2260-120-106-20100312) with ESMTP id <20100915063240.IGAT1489.viefep17-int.chello.at@edge04.upcmail.net>; Wed, 15 Sep 2010 08:32:40 +0200 Received: from wiesinger.com ([84.112.167.138]) by edge04.upcmail.net with edge id 6uYe1f01T2zVakc04uYfaw; Wed, 15 Sep 2010 08:32:40 +0200 X-SourceIP: 84.112.167.138 Received: from bbs.intern (localhost [127.0.0.1]) by wiesinger.com (8.14.4/8.14.4) with ESMTP id o8F6W00h028725; Wed, 15 Sep 2010 08:32:00 +0200 Received: from localhost (gerhard@localhost) by bbs.intern (8.14.4/8.14.4/Submit) with ESMTP id o8F6W0hZ028720; Wed, 15 Sep 2010 08:32:00 +0200 Date: Wed, 15 Sep 2010 08:32:00 +0200 (CEST) From: Gerhard Wiesinger To: Merlin Moncure cc: pgsql-performance@postgresql.org, Tom Lane , Pavel Stehule , Andreas Kretschmer Subject: Re: Major performance problem after upgrade from 8.3 to 8.4 In-Reply-To: Message-ID: References: <21281.1283433278@sss.pgh.pa.us> <22001.1283523290@sss.pgh.pa.us> <24994.1283532424@sss.pgh.pa.us> <25560.1283534215@sss.pgh.pa.us> <26620.1283537362@sss.pgh.pa.us> <27253.1283539468@sss.pgh.pa.us> <29799.1283548250@sss.pgh.pa.us> User-Agent: Alpine 2.01 (LFD 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-MailScanner-Information-wiesinger-com: Please contact the ISP for more information X-wiesinger-com-MailScanner-ID: o8F6W00h028725 X-MailScanner-wiesinger-com: Found to be clean X-MailScanner-SpamCheck-wiesinger-com: not spam, SpamAssassin (not cached, score=-4.399, required 4.5, autolearn=not spam, ALL_TRUSTED -1.80, BAYES_00 -2.60) X-MailScanner-From: lists@wiesinger.com X-Cloudmark-Analysis: v=1.1 cv=xhnIrgVimuy9wQ+RkywzulFXCq7zNkI+ObDjxzBho7Y= c=1 sm=0 a=-BBt41PQAQkA:10 a=wPDyFdB5xvgA:10 a=kj9zAlcOel0A:10 a=-ProOGmuAAAA:8 a=ObgIY8fb4iu6cHDte90A:9 a=Thqdmo6K3tv8Vw0-LDoA:7 a=0f7pkIL4PTPbMYgP-M9qPKWGdLgA:4 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.275 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_RP_RNBL=1.31, SARE_MILLIONSOF=0.315 X-Spam-Level: X-Archive-Number: 201009/82 X-Sequence-Number: 40285 On Tue, 14 Sep 2010, Merlin Moncure wrote: > np -- this felt particularly satisfying for some reason. btw, I think > you have some more low hanging optimization fruit. I think (although > it would certainly have to be tested) hiding your attribute > description under keyid is buying you nothing but headaches. If you > used natural key style, making description primary key of > key_description (or unique), and had log_details have a description > column that directly referenced that column, your subquery: > > ( > SELECT value FROM log_details d WHERE l.id = d.fk_id AND d.fk_keyid = > ( > SELECT keyid FROM key_description WHERE description = 'Kesselsolltemperatur' > ) > ) AS Kesselsolltemperatur, > > would look like this: > ( > SELECT value FROM log_details d WHERE l.id = d.fk_id AND > d.description = 'Kesselsolltemperatur' > ) AS Kesselsolltemperatur, > > your index on log_details(fk_id, description) is of course fatter, but > quite precise...does require rebuilding your entire dataset however. > food for thought. I think your suggestion might be slower because the WHERE clause and possible JOINS with BIGINT is much faster (especially when a lot of data is queried) than with a VARCHAR. With the latest query plan key_description is only queried once per subselect which is perfect. I've also chosen that indirection that I can change description without changing too much in data model and all data rows on refactoring. @Tom: Do you think of planner enhancements regarding such situations where JOINS are "converted" to subselects? BTW: I had a small bug in the queries and in the code that one description was wrong (one space too much: 'Meldung F4 2. Zeile' => 'Meldung F4 2. Zeile'). With this indirect data model this is very easy to change: Change the view and change one code line. With your suggested data model I would have to update millions of rows ... Ciao, Gerhard -- http://www.wiesinger.com/