Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id BE56A9FB740 for ; Mon, 30 Apr 2007 12:06:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 59716-01-9 for ; Mon, 30 Apr 2007 12:06:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DE0D39FB761 for ; Mon, 30 Apr 2007 12:06:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l3UF6lg5027304; Mon, 30 Apr 2007 11:06:47 -0400 (EDT) To: Andreas Haumer cc: pgsql-performance@postgresql.org Subject: Re: Query performance problems with partitioned tables In-reply-to: <4635D678.3050205@xss.co.at> References: <4635D678.3050205@xss.co.at> Comments: In-reply-to Andreas Haumer message dated "Mon, 30 Apr 2007 13:43:52 +0200" Date: Mon, 30 Apr 2007 11:06:47 -0400 Message-ID: <27303.1177945607@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/506 X-Sequence-Number: 24383 Andreas Haumer writes: > A simple example: Get the timestamp of a measurement value for time > series 3622 which is right before the measurement value with time > stamp '2007-04-22 00:00:00': > testdb_std=> select ts from mwdb.t_mv where zr=3622 and ts < '2007-04-22 00:00:00' order by ts desc limit 1; As already pointed out, this is only going to be able to exclude partitions that are strictly after the limit-time, since you have no WHERE clause that excludes anything before. Can you set a reasonable upper bound on the maximum inter-measurement time? If so, you could query something like this: select ts from mwdb.t_mv where zr=3622 and ts < '2007-04-22 00:00:00' and ts > '2007-04-21 00:00:00' order by ts desc limit 1; If you don't have a hard limit, but do have some smarts on the client side, you could try successive queries like this with larger and larger windows until you get an answer. regards, tom lane