Re: Aggregate View and Conditions taking FOREVER

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: illusina <illusina(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate View and Conditions taking FOREVER
Date: 2007-10-14 15:58:48
Message-ID: 27634.1192377528@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

illusina <illusina(at)hotmail(dot)com> writes:
> Ok..I've got a view which returns agency_id, fiscal_year, reporting_month,
> count_col0, count_col1...grouping by agency_id, fiscal_year and
> reporting_month. Now, if I just select * from myreport; it returns all the
> various counts for the various fiscal years and all that within 4 seconds,
> but if I add a conditional ie where fiscal_year = 2006 and reporting_month =
> 11, the query takes...10 minutes -- which I think is because the conditional
> cols (ie fiscal_year) is calculated via extract(year from datecol) which I
> think is causing that function to be checked on every row within the view.

Rather than guessing, how about showing EXPLAIN ANALYZE output for both
cases?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-10-14 16:14:40 Re: drop table cascade doesn't drop manual sequences
Previous Message Tom Lane 2007-10-14 15:56:27 Re: Using C API