Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A018C9FA060 for ; Wed, 12 Sep 2007 10:15:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 58770-01 for ; Wed, 12 Sep 2007 10:14:53 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id D89449FA026 for ; Wed, 12 Sep 2007 10:15:00 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IVS3P-0006mE-B6 for pgsql-performance@postgresql.org; Wed, 12 Sep 2007 15:14:51 +0200 Received: from cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk ([80.63.167.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Sep 2007 15:14:51 +0200 Received: from nis by cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Sep 2007 15:14:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: =?ISO-8859-1?Q?Nis_J=F8rgensen?= Subject: Re: 500rows = 1min/2.5k rows=20min/6K rows 2 hours and still running Date: Wed, 12 Sep 2007 15:14:25 +0200 Lines: 34 Message-ID: References: <1189529868.17184.17.camel@neuromancer.home.net> <1189530143.17184.21.camel@neuromancer.home.net> <15496.1189535000@sss.pgh.pa.us> <1189563332.32450.11.camel@neuromancer.home.net> <1189584573.13796.12.camel@neuromancer.home.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) In-Reply-To: <1189584573.13796.12.camel@neuromancer.home.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/223 X-Sequence-Number: 26768 El-Lotso skrev: > I'm on the verge of giving up... the schema seems simple and yet there's > so much issues with it. Perhaps it's the layout of the data, I don't > know. But based on the ordering/normalisation of the data and the one to > many relationship of some tables, this is giving the planner a headache > (and me a bulge on the head from knockin it against the wall) I think you should look more at the db design, and less on rewriting the query. Here are some observations: - Your table structure is quite hard to understand (possibly because you have changed the names) - if you want help on improving it, you will need to explain the data to us, and possibly post some sample data. - You seem to be lacking constraints on the tables. My guess is that (id,ttype,start_timestamp) is unique in both trh and ts - but I cannot tell (and neither can the query planner). Foreign key constraints might help as well. These would also help others to understand your data, and suggest reformulations of your queries. - Another guess is that the ttype sets (177,197,705,742,758,766), (69,178,198,704,757,741,765) are actually indicating some other property a common "type" of record, and that only one of each will be present for an id,start_timestamp combination. This may be related to the repeating fields issue - if a certain ttype indicates that we are interested in a certain pber_x field (and possibly that the others are empty). - You have what looks like repeating fields - pber_x, fval_x, index_x - in your tables. Fixing this might not improve your query, but might be a good idea for other reasons. - seq_date and seq_time seems like they may be redundant - are they different casts of the same data? All speculation. Hope it helps Nis