Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 890B41337B68 for ; Tue, 14 Sep 2010 03:09:02 -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 27811-09 for ; Tue, 14 Sep 2010 06:08:54 +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 4479A1337B7B for ; Tue, 14 Sep 2010 03:08:24 -0300 (ADT) Received: from edge03.upcmail.net ([192.168.13.238]) by viefep17-int.chello.at (InterMail vM.8.01.02.02 201-2260-120-106-20100312) with ESMTP id <20100914060820.YDKW1489.viefep17-int.chello.at@edge03.upcmail.net>; Tue, 14 Sep 2010 08:08:20 +0200 Received: from wiesinger.com ([84.112.167.138]) by edge03.upcmail.net with edge id 6W8E1f03o2zVakc03W8Feg; Tue, 14 Sep 2010 08:08:20 +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 o8E67OdM026445; Tue, 14 Sep 2010 08:07:24 +0200 Received: from localhost (gerhard@localhost) by bbs.intern (8.14.4/8.14.4/Submit) with ESMTP id o8E67IlO026430; Tue, 14 Sep 2010 08:07:21 +0200 Date: Tue, 14 Sep 2010 08:07:18 +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: <11111.1283185373@sss.pgh.pa.us> <12837.1283186981@sss.pgh.pa.us> <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: o8E67OdM026445 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=DaemWvOqUMXtZrsnbTMA:9 a=0FhCgOWsyfF846A7hR4A:7 a=xzu0Da8nH6_Kws5ao11i7HXT3uIA:4 a=CjuIK1q_8ugA:10 a=fU-A4pz3-wIA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.59 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_RP_RNBL=1.31 X-Spam-Level: X-Archive-Number: 201009/70 X-Sequence-Number: 40273 Hello Merlin, Seems to be a feasible approach. On problem which might be that when multiple rows are returned that they are not ordered in each subselect correctly. Any idea to solve that? e.g. Raumsolltemperatur | Raumisttemperatur Value from time 1 | Value from time 2 Value from time 2 | Value from time 1 but should be Raumsolltemperatur | Raumisttemperatur Value from time 1 | Value from time 1 Value from time 2 | Value from time 2 But that might be solveable by first selecting keys from the log_details table and then join again. I will try it in the evening and I have to think about in detail. But thank you for the new approach and opening the mind :-) Ciao, Gerhard -- http://www.wiesinger.com/ On Mon, 13 Sep 2010, Merlin Moncure wrote: > On Mon, Sep 13, 2010 at 2:39 AM, Gerhard Wiesinger wrote: >> Hello, >> >> Any news or ideas regarding this issue? > > hm. is retooling the query an option? specifically, can you try converting > > CREATE OR REPLACE VIEW log_entries AS > SELECT > l.id AS id, > l.datetime AS datetime, > l.tdate AS tdate, > l.ttime AS ttime, > d1.value AS Raumsolltemperatur, > [...] > FROM > log l > LEFT JOIN log_details d1 ON l.id = d1.fk_id AND > d1.fk_keyid = (SELECT keyid FROM key_description WHERE description = > 'Raumsolltemperatur') > [...] > > to > > CREATE OR REPLACE VIEW log_entries AS > SELECT > l.id AS id, > l.datetime AS datetime, > l.tdate AS tdate, > l.ttime AS ttime, > (select value from log_details ld join key_description kd on > ld.fk_keyid = kd.keyid where ld.fk_id = l.id and description = > 'Raumsolltemperatur') AS Raumsolltemperatur, > [...] > > (I am not 100% sure I have your head around your query, but I think I do)? > This should get you a guaranteed (although not necessarily 'the best' > plan, with each returned view column being treated independently of > the other (is that what you want?). Also, if schema changes are under > consideration, you can play log_details/key_description, using natural > key and cut out one of the joins. I can't speak to some of the more > complex planner issues at play, but your query absolutely screams > optimization at the SQL level. > > What I am 100% sure of, is that you can get better performance if you > do a little out of the box thinking here... > > merlin >