From: | Bricklen Anderson <banderson(at)presinet(dot)com> |
---|---|
To: | kevin kempter <kevin(at)kevinkempterllc(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Partitioned tables - planner wont use indexes |
Date: | 2008-04-07 15:52:50 |
Message-ID: | 47FA4352.5050309@presinet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
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<min_date)) THEN
min_date := min_date_tmp;
END IF;
END LOOP;
RETURN min_date;
END;
$_$ language plpgsql immutable;
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew | 2008-04-07 16:19:27 | Re: Severe performance problems for simple query |
Previous Message | Matt Klinker | 2008-04-07 15:46:38 | Re: [SOLVED] Query plan excluding index on view |