Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 773B32E003A for ; Mon, 7 Apr 2008 13:08:17 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 07273-10 for ; Mon, 7 Apr 2008 13:08:14 -0300 (ADT) X-Greylist: delayed 00:12:15.879107 by SQLgrey-1.7.5 Received: from presinet.com (mail.presinet.com [209.53.156.1]) by developer.postgresql.org (Postfix) with ESMTP id A0AA42E0039 for ; Mon, 7 Apr 2008 13:08:14 -0300 (ADT) Received: from [10.10.1.151] ([10.10.1.151]) by presinet.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 7 Apr 2008 08:58:30 -0700 Message-ID: <47FA4352.5050309@presinet.com> Date: Mon, 07 Apr 2008 08:52:50 -0700 From: Bricklen Anderson User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: kevin kempter CC: pgsql-performance@postgresql.org Subject: Re: Partitioned tables - planner wont use indexes References: In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 07 Apr 2008 15:58:30.0828 (UTC) FILETIME=[39A86EC0:01C898C8] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/57 X-Sequence-Number: 29550 kevin kempter wrote: > One of the things we need to query is the min date from the master table > - we may explore alternatives for this particular query, however even if > we fix this query I think we have a fundamental issue with the use of > indexes (actuallt the non-use) by the planner. We had a similar requirement, so I've been using a function that loops over the child tables, and queries for the min date from each. If all you need is the date, you can try a function call. Here is a modified version of what I've been using: CREATE OR REPLACE function get_min_date() RETURNS DATE as $_$ DECLARE x RECORD; min_date DATE; min_date_tmp DATE; qry TEXT; BEGIN /* can also test MIN() aggregate, rather than ORDER BY/LIMIT */ FOR x IN EXECUTE 'select tablename from pg_tables where tablename like ''part_20%''' loop qry := 'SELECT logdate FROM '||x.tablename||' ORDER BY logdate LIMIT 1'; EXECUTE qry INTO min_date_tmp; IF (min_date IS NULL OR (min_date_tmp IS NOT NULL AND min_date_tmp