Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B168C9FB6E6 for ; Mon, 30 Apr 2007 13:58:23 -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 80850-01 for ; Mon, 30 Apr 2007 13:58:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from bernhard.xss.co.at (bernhard.xss.co.at [193.80.108.69]) by postgresql.org (Postfix) with ESMTP id 9B65A9FB5DE for ; Mon, 30 Apr 2007 13:58:19 -0300 (ADT) Received: from schiller.intern.xss.co.at ([192.168.162.2]) by bernhard.xss.co.at (8.13.8/8.13.8) with ESMTP id l3UGwF4F000865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Apr 2007 18:58:15 +0200 Received: from [192.168.162.51] (ws1.intern.xss.co.at [192.168.162.51]) (authenticated bits=0) by schiller.intern.xss.co.at (8.13.8/8.13.8) with ESMTP id l3UGwF6p021238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 30 Apr 2007 18:58:16 +0200 Message-ID: <46362027.9000803@xss.co.at> Date: Mon, 30 Apr 2007 18:58:15 +0200 From: Andreas Haumer Organization: xS+S User-Agent: Thunderbird 1.5.0.9 (X11/20061206) MIME-Version: 1.0 To: Neil Peter Braggio CC: pgsql-performance@postgresql.org Subject: Re: Query performance problems with partitioned tables References: <4635D678.3050205@xss.co.at> <87ps5mgghp.fsf@meuh.mnc.lan> <4635EF3A.1070204@xss.co.at> <4635F2E1.3090602@archonet.com> In-Reply-To: X-Enigmail-Version: 0.94.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/509 X-Sequence-Number: 24386 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! Neil Peter Braggio schrieb: > Just cast the value in the WHERE clause: > > select ts from mwdb.t_mv where zr=3622 and ts > '2006-01-01 00:00:00' > ::TIMESTAMP order by ts asc limit 1; > > This search only into the right partitioned tables if you build the > rules based in the ts field. > This doesn't help. A cast is not needed in this case, as the following query shows, where the query planner already is able to reduce the scan to the right tables: testdb_part=> select ts from mwdb.t_mv where zr=3622 and ts > '2005-12-31 22:00:00' and ts < '2006-01-01 02:00:00'; ts - ------------------------ 2005-12-31 23:00:00+01 2006-01-01 00:00:00+01 2006-01-01 01:00:00+01 (3 rows) testdb_part=> explain analyze select ts from mwdb.t_mv where zr=3622 and ts > '2005-12-31 22:00:00' and ts < '2006-01-01 02:00:00'; QUERY PLAN - ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Result (cost=0.00..26.64 rows=4 width=8) (actual time=0.040..0.088 rows=3 loops=1) -> Append (cost=0.00..26.64 rows=4 width=8) (actual time=0.035..0.071 rows=3 loops=1) -> Index Scan using i_mv_ts on t_mv (cost=0.00..8.27 rows=1 width=8) (actual time=0.010..0.010 rows=0 loops=1) Index Cond: (((ts)::timestamp with time zone > '2005-12-31 22:00:00+01'::timestamp with time zone) AND ((ts)::timestamp with time zone < '2006-01-01 02:00:00+01'::timestamp with time zone)) Filter: ((zr)::integer = 3622) -> Index Scan using pk_mv_200512 on t_mv_200512 t_mv (cost=0.00..8.30 rows=1 width=8) (actual time=0.019..0.022 rows=1 loops=1) Index Cond: (((zr)::integer = 3622) AND ((ts)::timestamp with time zone > '2005-12-31 22:00:00+01'::timestamp with time zone) AND ((ts)::timestamp with time zone < '2006-01-01 02:00:00+01'::timestamp with time zone)) -> Index Scan using pk_mv_200601 on t_mv_200601 t_mv (cost=0.00..10.07 rows=2 width=8) (actual time=0.014..0.019 rows=2 loops=1) Index Cond: (((zr)::integer = 3622) AND ((ts)::timestamp with time zone > '2005-12-31 22:00:00+01'::timestamp with time zone) AND ((ts)::timestamp with time zone < '2006-01-01 02:00:00+01'::timestamp with time zone)) Total runtime: 0.176 ms (10 rows) Here, two child tables are involved (t_mv_200512 and t_mv_200601) and the query only uses those two, even without cast of the constants in the where clause. - - andreas - -- Andreas Haumer | mailto:andreas@xss.co.at *x Software + Systeme | http://www.xss.co.at/ Karmarschgasse 51/2/20 | Tel: +43-1-6060114-0 A-1100 Vienna, Austria | Fax: +43-1-6060114-71 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGNiATxJmyeGcXPhERAo23AJwPCBwvWQT/m3QRXRWqK0aECeMQ2gCbBDjA E5iZNnU41vrFBNtXzdCSmWY= =0+pC -----END PGP SIGNATURE-----